Jump to content

Weapon which deals different damage based on Moon Phase


Recommended Posts

...is what I've been trying to make. However... it isn't working.

I have the weapon in the game fully, but the damage keeps staying the same. Other than for the full moon, strangely. I think I'm doing what I'm supposed to, comparing it to the Moondial. Anyway, here's my code. (There are a few redundancies, though)

 

local assets =
{
    Asset("ANIM", "anim/moonsword.zip"),
    Asset("ANIM", "anim/swap_moonsword.zip"),
	
	Asset("ATLAS", "images/inventoryimages/moonsword.xml"),
    Asset("IMAGE", "images/inventoryimages/moonsword.tex"),
}

local prefabs = 
{
}

local function UpdateDamage(inst)
    if inst.components.weapon then
	  if TheWorld.state.moonphase == "full" then
	    inst.components.weapon:SetDamage(76.8)
	  elseif TheWorld.state.moonphase == "threequarters" then
	    inst.components.weapon:SetDamage(68)
	  elseif TheWorld.state.moonphase == "half" then
	    inst.components.weapon:SetDamage(59.5)
	  elseif TheWorld.state.moonphase == "quarter" then
	    inst.components.weapon:SetDamage(51)
	  elseif TheWorld.state.moonphase == "new" then
	    inst.components.weapon:SetDamage(42.5)
	  else
	    inst.components.weapon:SetDamage(1)
	  end
    end
end

local function onmoonphasechagned(inst, phase)
    UpdateDamage(inst)
end

local function OnLoad(inst, data)
    UpdateDamage(inst)
end

local function OnEquip(inst, owner)
    onmoonphasechagned(inst)
    owner.AnimState:OverrideSymbol("swap_object", "swap_moonsword", "moonsword")
    owner.AnimState:Show("ARM_carry")
    owner.AnimState:Hide("ARM_normal")
	UpdateDamage(inst)
end

local function OnUnequip(inst, owner)
    owner.AnimState:Hide("ARM_carry")
    owner.AnimState:Show("ARM_normal")
	UpdateDamage(inst)
end

local function fn()
    
	local inst = CreateEntity()
    local trans = inst.entity:AddTransform()
    local anim = inst.entity:AddAnimState()
    MakeInventoryPhysics(inst)

    inst.AnimState:SetBank("moonsword")
    inst.AnimState:SetBuild("moonsword")
    inst.AnimState:PlayAnimation("idle")
    inst.AnimState:SetMultColour(1, 1, 1, .7)

    inst.entity:SetPristine()

    if not TheWorld.ismastersim then
        return inst
    end

    inst:AddComponent("weapon")
    inst.components.weapon:SetDamage(42.5)
    inst.components.weapon:SetOnAttack(UpdateDamage)

    inst.OnLoad = OnLoad
	
	--Uses?
	inst:AddComponent("finiteuses")
    inst.components.finiteuses:SetMaxUses(200)
    inst.components.finiteuses:SetUses(200)
	inst.components.finiteuses:SetOnFinished(inst.Remove)

    inst:AddComponent("inspectable")
	STRINGS.NAMES.MOONSWORD = "Moon Sword"
    STRINGS.CHARACTERS.GENERIC.DESCRIBE.MOONSWORD = "It strikes with the light of the moon."

    inst:AddComponent("inventoryitem")
	inst.components.inventoryitem.imagename = "moonsword"
    inst.components.inventoryitem.atlasname = "images/inventoryimages/moonsword.xml"
	
	inst:AddTag("sharp")
	
	--MOON STUFF
	inst:WatchWorldState("moonphase", onmoonphasechagned)
    onmoonphasechagned(inst)
	
	MakeHauntableLaunch(inst)

    inst:AddComponent("equippable")
    inst.components.equippable:SetOnEquip( OnEquip )
    inst.components.equippable:SetOnUnequip( OnUnequip )
	inst.components.equippable.dapperness = TUNING.DAPPERNESS_MED

    return inst
end

return Prefab( "moonsword", fn, assets, prefabs) 


Does anyone know why this isn't working?

Link to comment
Share on other sites

Nope. Looks like it should work. Time to do some print("What the hell is going on 1")

Why don't you just start listening for the moonphase changes in the fn() and call UpdateDamage whenever it changes? It seems a huge waste to call the function every time you attack or equip it and all that. Of course also call it manually in fn() itself.

Link to comment
Share on other sites

I don't know what 

Quote

this isn't working?

means. 

Will it cause a crash or your moonphase stuff does not work?
If then, you have to write that information.
Or people who try to help would be confused at don't know what exactly the problem is.
Please describe what just happened and give more information as far as you know.
Because your code seems to have no problem.

Edited by YakumoYukari
Link to comment
Share on other sites

Thank you for the help, it seems that it actually WAS working the whole time... however, a combination of me typing "threequarters" instead of "threequarter" made the damage not update for those phases, and the way I was checking the damage of the sword (using the mod "Item Info") didn't actually show the damage update, so I assumed it was broken... Thanks for suggesting all the print statements. That combined with the Target Dummy (Which I didn't know existed! But it is very useful!) helped me figure out what was going on. Thanks again!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...