Skip to content

Commit

Permalink
throw to talk
Browse files Browse the repository at this point in the history
  • Loading branch information
zombieJ committed Jul 26, 2021
1 parent 69bb1b4 commit b2d22ba
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
12 changes: 7 additions & 5 deletions scripts/behaviours/aipThrowBall.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@ function ThrowBall:__tostring()
return string.format("target %s", tostring(self.target))
end

local MUST_TAGS = { "aip_score_ball" }

function ThrowBall:Visit()
if self.status == READY then
self.target = nil
local x, y, z = self.inst.Transform:GetWorldPosition()

local balls = TheSim:FindEntities(x, 0, z, 15, MUST_TAGS)
local balls = TheSim:FindEntities(x, 0, z, 10, { "aip_score_ball" })
for i, ball in ipairs(balls) do
if ball.components.aipc_score_ball:CanFollow() then
self.target = ball
Expand Down Expand Up @@ -43,8 +41,8 @@ function ThrowBall:Visit()
else
local target_position = Point(self.target.Transform:GetWorldPosition())
self.inst.components.locomotor:GoToPoint(
self.target.components.aipc_score_ball:PredictPoint(0.1),
-- target_position,
-- self.target.components.aipc_score_ball:PredictPoint(0.3),
target_position,
nil,
true
)
Expand All @@ -53,6 +51,10 @@ function ThrowBall:Visit()
if self.target.components.aipc_score_ball:CanThrow() and distsq(target_position, me) < 1 then
self.inst:PushEvent("throw", {target = self.target})
self.inst.components.timer:StartTimer("aip_mini_dou_dall_throw", 2)

if self.inst.components.talker ~= nil then
self.inst.components.talker:Say(STRINGS.AIP_MINI_DOUJIANG_THROW_BALL)
end
end

-- -- 不知道干啥的,就当优化用了
Expand Down
10 changes: 7 additions & 3 deletions scripts/components/aipc_score_ball.lua
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,19 @@ end
function ScoreBall:CanFollow()
local x, y, z = self.ball.Transform:GetWorldPosition()
-- 球下落中 或者 飞起一段距离后
return (self.startTimes == 1 and (self.downTimes == 1 or y > 7)) or (
self.startTimes == 2 and self.downTimes == 1
return (
(self.startTimes == 1 and (self.downTimes == 1 or y > 7)) or -- 第一次飞起 7 高度或下落中
(self.startTimes == 2 and self.downTimes == 1) -- 第二次飞起
)
end

-- 若光可以击球
function ScoreBall:CanThrow()
local x, y, z = self.ball.Transform:GetWorldPosition()
return self:CanFollow() and y < 2
return self:CanFollow() and (
(self.downTimes == 1 and y < 1.5) or -- 第一次下落至 1.5 高度
(self.startTimes == 2 and y < 1.5) -- 第二次 1.5 高度内
)
end

function ScoreBall:OnUpdate(dt)
Expand Down
14 changes: 11 additions & 3 deletions scripts/prefabs/aip_mini_doujiang.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ local LANG_MAP = {
NEED_RECIPE = "Are you ingenuity?",
REQUIRE_PLAY = "Throw it to me~",
BYE = "Bye~",
YOU_FIRST = "You first~",
THROW_BALL = "I got it!",
},
chinese = {
NAME = "若光",
DESC = "可爱的小家伙",
NEED_RECIPE = "你会做豆豆球吗?",
REQUIRE_PLAY = "把球打给我吧~",
BYE = "要走了吗?",
YOU_FIRST = "你先来~",
THROW_BALL = "嗷呜!",
},
}

Expand All @@ -39,16 +39,24 @@ STRINGS.CHARACTERS.GENERIC.DESCRIBE.AIP_MINI_DOUJIANG = LANG.DESC
STRINGS.AIP_MINI_DOUJIANG_NEED_RECIPE = LANG.NEED_RECIPE
STRINGS.AIP_MINI_DOUJIANG_REQUIRE_PLAY = LANG.REQUIRE_PLAY
STRINGS.AIP_MINI_DOUJIANG_BYE = LANG.BYE
STRINGS.AIP_MINI_DOUJIANG_YOU_FIRST = LANG.YOU_FIRST
STRINGS.AIP_MINI_DOUJIANG_THROW_BALL = LANG.THROW_BALL

------------------------------- 方法 -------------------------------
-- 玩家靠近
local function onNear(inst, player)
-- 如果附近有球就不提示了
local x, y, z = inst.Transform:GetWorldPosition()
local balls = TheSim:FindEntities(x, 0, z, 10, { "aip_score_ball" })
if #balls > 0 then
return
end

inst:DoTaskInTime(1, function()
if
player and not player.components.builder:KnowsRecipe("aip_score_ball") and
not inst.components.timer:TimerExists("aip_mini_dou_dall_blueprints")
then
-- 如果玩家不会制作球就提供一个图纸
inst.components.timer:StartTimer("aip_mini_dou_dall_blueprints", 300)
inst.components.lootdropper:SpawnLootPrefab("aip_score_ball_blueprint")
inst.components.talker:Say(STRINGS.AIP_MINI_DOUJIANG_NEED_RECIPE)
Expand Down

0 comments on commit b2d22ba

Please sign in to comment.