private void LoadNodeLevelsFromSave(ArchetypeSkillNode node, int initalLevel, int setLevel)
    {
        if (node == null)
        {
            return;
        }
        if (initalLevel == setLevel)
        {
            return;
        }

        hero.ModifyArchetypePoints(-(setLevel - initalLevel));

        if (node.type == NodeType.ABILITY && setLevel >= 1)
        {
            AvailableAbilityList.Add(node.GetAbility());
        }

        foreach (var bonus in node.bonuses)
        {
            float bonusValue = 0f;
            if (setLevel > initalLevel)
            {
                if (setLevel == 1 && node.maxLevel == 1)
                {
                    bonusValue = bonus.growthValue;
                }
                else if (setLevel == node.maxLevel)
                {
                    int difference = setLevel - initalLevel - 1;
                    bonusValue = bonus.growthValue * difference + bonus.finalLevelValue;
                }
                else
                {
                    int difference = setLevel - initalLevel;
                    bonusValue = bonus.growthValue * difference;
                }
                hero.AddArchetypeStatBonus(bonus.bonusType, bonus.restriction, bonus.modifyType, bonusValue);
            }
        }

        foreach (TriggeredEffectBonusProperty triggeredEffectBonus in node.triggeredEffects)
        {
            TriggeredEffect t = new TriggeredEffect(triggeredEffectBonus, triggeredEffectBonus.effectMinValue, node.idName);
            hero.AddTriggeredEffect(triggeredEffectBonus, t);
        }

        nodeLevels[node.id] = setLevel;
        AllocatedPoints    += setLevel;
    }
 public void InitializeNodeLevels()
 {
     foreach (var node in Base.nodeList)
     {
         int level = node.initialLevel;
         if (node.type == NodeType.ABILITY && level >= 1)
         {
             AvailableAbilityList.Add(node.GetAbility());
         }
         else if (level == 1)
         {
             foreach (var bonus in node.bonuses)
             {
                 hero.AddArchetypeStatBonus(bonus.bonusType, bonus.restriction, bonus.modifyType, bonus.growthValue);
             }
         }
         nodeLevels.Add(node.id, level);
     }
 }
    public void InitializeArchetypeData()
    {
        HealthGrowth       = Base.healthGrowth;
        SoulPointGrowth    = Base.soulPointGrowth;
        StrengthGrowth     = Base.strengthGrowth;
        IntelligenceGrowth = Base.intelligenceGrowth;
        AgilityGrowth      = Base.agilityGrowth;
        WillGrowth         = Base.willGrowth;
        AllocatedPoints    = 0;
        nodeLevels         = new Dictionary <int, int>();

        AbilityBase soulAbilityBase = Base.GetSoulAbility();

        if (soulAbilityBase != null)
        {
            AvailableAbilityList.Add(soulAbilityBase);
        }


        InitializeNodeLevels();
    }
    public bool DelevelNode(ArchetypeSkillNode node)
    {
        if (nodeLevels[node.id] == node.initialLevel)
        {
            return(false);
        }

        if (node.type == NodeType.ABILITY)
        {
            var ability = AvailableAbilityList.GetAbility(node.GetAbility());
            if (ability.equippedHero != null)
            {
                hero.UnequipAbility(ability.equippedSlot);
            }
            AvailableAbilityList.Remove(node.GetAbility());
        }

        foreach (var bonus in node.bonuses)
        {
            float bonusValue = 0f;
            if (bonus.modifyType != ModifyType.MULTIPLY)
            {
                if (nodeLevels[node.id] == 1)
                {
                    bonusValue = bonus.growthValue;
                }
                else if (nodeLevels[node.id] == node.maxLevel)
                {
                    bonusValue = bonus.finalLevelValue;
                }
                else
                {
                    bonusValue = bonus.growthValue;
                }

                hero.RemoveArchetypeStatBonus(bonus.bonusType, bonus.restriction, bonus.modifyType, bonusValue);
            }
            else
            {
                if (nodeLevels[node.id] == 1)
                {
                    bonusValue = bonus.growthValue;
                }
                else if (nodeLevels[node.id] == node.maxLevel)
                {
                    bonusValue = bonus.growthValue * (nodeLevels[node.id] - 1) + bonus.finalLevelValue;
                    hero.AddArchetypeStatBonus(bonus.bonusType, bonus.restriction, bonus.modifyType, bonus.growthValue * (nodeLevels[node.id] - 1));
                }
                else
                {
                    bonusValue = bonus.growthValue * nodeLevels[node.id];
                    hero.AddArchetypeStatBonus(bonus.bonusType, bonus.restriction, bonus.modifyType, bonus.growthValue * (nodeLevels[node.id] - 1));
                }

                hero.RemoveArchetypeStatBonus(bonus.bonusType, bonus.restriction, bonus.modifyType, bonusValue);
            }
        }

        if (nodeLevels[node.id] == 1)
        {
            foreach (TriggeredEffectBonusProperty triggeredEffectBonus in node.triggeredEffects)
            {
                hero.RemoveTriggeredEffect(triggeredEffectBonus);
            }
        }
        nodeLevels[node.id]--;
        AllocatedPoints--;

        hero.UpdateActorData();
        return(true);
    }
    public bool LevelUpNode(ArchetypeSkillNode node)
    {
        if (nodeLevels[node.id] == node.maxLevel)
        {
            return(false);
        }
        nodeLevels[node.id]++;
        AllocatedPoints++;
        if (node.type == NodeType.ABILITY)
        {
            AvailableAbilityList.Add(node.GetAbility());
        }
        foreach (var bonus in node.bonuses)
        {
            float bonusValue = 0f;
            if (bonus.modifyType != ModifyType.MULTIPLY)
            {
                if (nodeLevels[node.id] == 1)
                {
                    bonusValue = bonus.growthValue;
                }
                else if (nodeLevels[node.id] == node.maxLevel)
                {
                    bonusValue = bonus.finalLevelValue;
                }
                else
                {
                    bonusValue = bonus.growthValue;
                }

                hero.AddArchetypeStatBonus(bonus.bonusType, bonus.restriction, bonus.modifyType, bonusValue);
            }
            else
            {
                if (nodeLevels[node.id] == 1)
                {
                    bonusValue = bonus.growthValue;
                }
                else if (nodeLevels[node.id] == node.maxLevel)
                {
                    bonusValue = bonus.growthValue * (nodeLevels[node.id] - 1) + bonus.finalLevelValue;
                    hero.RemoveArchetypeStatBonus(bonus.bonusType, bonus.restriction, bonus.modifyType, bonus.growthValue * (nodeLevels[node.id] - 1));
                }
                else
                {
                    bonusValue = bonus.growthValue * nodeLevels[node.id];
                    hero.RemoveArchetypeStatBonus(bonus.bonusType, bonus.restriction, bonus.modifyType, bonus.growthValue * (nodeLevels[node.id] - 1));
                }

                hero.AddArchetypeStatBonus(bonus.bonusType, bonus.restriction, bonus.modifyType, bonusValue);
            }
        }

        if (nodeLevels[node.id] == 1)
        {
            foreach (TriggeredEffectBonusProperty triggeredEffectBonus in node.triggeredEffects)
            {
                TriggeredEffect t = new TriggeredEffect(triggeredEffectBonus, triggeredEffectBonus.effectMinValue, node.idName);
                hero.AddTriggeredEffect(triggeredEffectBonus, t);
            }
        }

        hero.UpdateActorData();

        return(true);
    }