Skip to content

Commit

Permalink
refactor: Replace xiyou cards from fuel to recharge
Browse files Browse the repository at this point in the history
  • Loading branch information
zombieJ committed Sep 11, 2021
1 parent 206ab77 commit 59f53bb
Showing 1 changed file with 28 additions and 35 deletions.
63 changes: 28 additions & 35 deletions scripts/prefabs/aip_xiyou_cards.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ local DIGEST_SPEED = {
["normal"] = TUNING.SEG_TIME * 5,
["large"] = TUNING.SEG_TIME * 1,
}
local fuelValue = DIGEST_SPEED[weapon_damage] * (dev_mode and 0.1 or 1)
local fuelValue = DIGEST_SPEED[weapon_damage] * (dev_mode and 0.02 or 1)

-- 资源
local assets = {
Expand All @@ -32,14 +32,12 @@ local LANG_MAP = {
NAME = "Myth Cards",
DESC = "Exquisite card",
SPEACH = "Shadow go away!",
FULL = "It's full!",
},
chinese = {
NAME = "神话书说卡组",
DESC = "装订成册的精致卡组",
DESC_MYTH = "这样就把我们都集齐啦",
SPEACH = "邪魅退散!",
FULL = "它还没消化完",
},
}

Expand All @@ -49,23 +47,32 @@ STRINGS.NAMES.AIP_XIYOU_CARDS = LANG.NAME
STRINGS.CHARACTERS.GENERIC.DESCRIBE.AIP_XIYOU_CARDS = LANG.DESC
STRINGS.CHARACTERS.GENERIC.DESCRIBE.AIP_XIYOU_CARDS_MYTH = LANG.DESC_MYTH
STRINGS.CHARACTERS.GENERIC.DESCRIBE.AIP_XIYOU_CARDS_SPEACH = LANG.SPEACH
STRINGS.CHARACTERS.GENERIC.DESCRIBE.AIP_XIYOU_CARDS_FULL = LANG.FULL

----------------------------------- 方法 -----------------------------------
-- 更新充能状态
local function refreshStatus(inst)
-- 更新贴图
if inst.components.fueled:IsEmpty() then
inst.components.inventoryitem.atlasname = "images/inventoryimages/aip_xiyou_cards.xml"
inst.components.inventoryitem:ChangeImageName("aip_xiyou_cards")
inst.AnimState:PlayAnimation("book", false)
else
if inst.components.rechargeable:IsCharged() then
inst.components.inventoryitem.atlasname = "images/inventoryimages/aip_xiyou_cards_charge.xml"
inst.components.inventoryitem:ChangeImageName("aip_xiyou_cards_charge")
inst.AnimState:PlayAnimation("book_charge", true)
else
inst.components.inventoryitem.atlasname = "images/inventoryimages/aip_xiyou_cards.xml"
inst.components.inventoryitem:ChangeImageName("aip_xiyou_cards")
inst.AnimState:PlayAnimation("book", false)
end
end

local function onDischarged(inst)
inst:RemoveTag("aip_readable")
refreshStatus(inst)
end

local function onCharged(inst)
inst:AddTag("aip_readable")
refreshStatus(inst)
end

-- 获取描述
local function getDesc(inst, viewer)
if aipInTable(charactersList, viewer.prefab) then
Expand All @@ -77,17 +84,12 @@ end

-- 是否可以阅读
local function canBeRead(inst, doer)
return true
return inst:HasTag("aip_readable")
end

-- 吸收附近的暗影怪 444 点生命值,如果有多个则平均分摊
local function onDoRead(inst, doer)
if not inst.components.fueled:IsEmpty() then
-- 说一句酷炫的话
if doer.components.talker ~= nil then
doer.components.talker:Say(STRINGS.CHARACTERS.GENERIC.DESCRIBE.AIP_XIYOU_CARDS_FULL)
end

if not inst.components.rechargeable:IsCharged() then
return
end

Expand All @@ -105,31 +107,19 @@ local function onDoRead(inst, doer)

-- 对生物造成伤害
if #shadowCreatures > 0 then
inst.components.rechargeable:Discharge(fuelValue)

local avgDmg = 444 / #shadowCreatures
for i, creature in ipairs(shadowCreatures) do
creature.components.combat:GetAttacked(doer, avgDmg)

-- 特效
local proj = aipSpawnPrefab(creature, "aip_projectile")
proj.components.aipc_projectile.speed = 15
proj.components.aipc_info_client:SetByteArray( -- 调整颜色
"aip_projectile_color", { 0, 0, 0, 5 }
)
proj.components.aipc_projectile:GoToTarget(doer, function()
-- 充满
inst.components.fueled:DoDelta(fuelValue / #shadowCreatures)
inst.components.fueled:StartConsuming()
refreshStatus(inst)
end)

-- 爆炸效果
aipSpawnPrefab(creature, "aip_shadow_wrapper").DoShow()
end
end
end

local function onDepleted(inst)
-- inst.components.lootdropper:SpawnLootPrefab("nightmarefuel")
refreshStatus(inst)
end

Expand All @@ -148,6 +138,8 @@ function fn()
inst.AnimState:SetBuild("aip_xiyou_card")
inst.AnimState:PlayAnimation("book")

inst:AddTag("aip_readable")

inst.entity:SetPristine()

inst:AddComponent("aipc_action_client")
Expand All @@ -163,11 +155,9 @@ function fn()
inst:AddComponent("lootdropper")
inst.components.lootdropper:SetLoot({})

inst:AddComponent("fueled")
inst.components.fueled.fueltype = FUELTYPE.MAGIC
inst.components.fueled.maxfuel = fuelValue
inst.components.fueled.depleted = onDepleted
inst.components.fueled:InitializeFuelLevel(0)
inst:AddComponent("rechargeable")
inst.components.rechargeable:SetOnDischargedFn(onDischarged)
inst.components.rechargeable:SetOnChargedFn(onCharged)

inst:AddComponent("aipc_action")
inst.components.aipc_action.onDoAction = onDoRead
Expand All @@ -182,6 +172,9 @@ function fn()
MakeSmallBurnable(inst, TUNING.SMALL_BURNTIME)
MakeSmallPropagator(inst)

inst:DoTaskInTime(0.1, refreshStatus)
-- inst.components.rechargeable:Discharge(0.1)

return inst
end

Expand Down

0 comments on commit 59f53bb

Please sign in to comment.