// ===============================================================================
        // AI FUNCTIONS
        // ===============================================================================

        // -------------------------------------------------------------------------------
        // ProcessEnemyTurn
        // -------------------------------------------------------------------------------
        public void EnemyTurn()
        {
            if (IsAlive)
            {
                // -- Stun check
                if (buffs.Any(x => x.template.statModifiers.special.stun == true) || IsFleeing)
                {
                    ActionPassTurn();
                }

                /*
                 * this can be replaced with a proper AI later
                 */

                if (UnityEngine.Random.value <= .3)
                {
                    int c = abilities.Count;

                    if (c > 0)
                    {
                        for (int i = 0; i < c; i++)
                        {
                            if (CanCastAbility(abilities[i].template, abilities[i].level))
                            {
                                CommandCastSpell(abilities[i], RPGHelper.getRandomPlayer());
                                return;
                            }
                        }
                    }
                }

                CommandAttack(RPGHelper.getRandomPlayer()  );
            }
        }
        // ===============================================================================
        // INITIALIZATION
        // ===============================================================================

        // -------------------------------------------------------------------------------
        // DefaultInitialize
        // -------------------------------------------------------------------------------
        public override void DefaultInitialize()
        {
            base.DefaultInitialize();

            parent.GetComponent <MonsterPanel>().DefaultInitialize(this);
            stats.XP            = CalculateMonsterXP();
            AttributePoints     = 0;
            AbilityPoints       = 0;
            stats.XPToNextLevel = RPGHelper.NextLvlExp(Level);
        }
        // -------------------------------------------------------------------------------
        //
        // -------------------------------------------------------------------------------
        protected void GainLoot()
        {
            List <LootDrop> lootdrop = new List <LootDrop>();

            foreach (CharacterMonster monster in monsterParty.characters)
            {
                lootdrop.AddRange(monster.lootContent);
            }

            RPGHelper.DropLoot(lootdrop);
        }
        // -------------------------------------------------------------------------------
        // DefaultInitialize
        // -------------------------------------------------------------------------------
        public override void DefaultInitialize()
        {
            base.DefaultInitialize();

            Finder.navi.PlayerMoved += playerNavigation_PlayerMoved;

            AttributePoints = 0;
            AbilityPoints   = 0;

            stats.XPToNextLevel = RPGHelper.NextLvlExp(Level);
        }
Ejemplo n.º 5
0
        // -------------------------------------------------------------------------------
        // DamageTargets
        // -------------------------------------------------------------------------------
        public static void DamageTargets(CharacterBase source, InstanceBase activator, int amount, CharacterBase[] targets)
        {
            foreach (CharacterBase target in targets)
            {
                if (target != null)
                {
                    int level = 0;

                    int accuracy = 0;
                    TemplateAdvanced template = null;

                    if (activator is InstanceItem)
                    {
                        template = ((InstanceItem)activator).template;
                        //level = ((InstanceItem)activator).level;
                    }
                    else if (activator is InstanceSkill)
                    {
                        template = ((InstanceSkill)activator).template;
                        level    = ((InstanceSkill)activator).level;
                    }

                    amount += template.CalculatedEffect(source, target, level);

                    if (source != null)
                    {
                        accuracy = source.stats.Accuracy;
                    }

                    amount = RPGHelper.CalculateFinalDamage(amount, template.attackType, template.element, target);

                    if (source != null)
                    {
                        amount += source.CalculateHitType(amount, target, template);
                    }

                    target.InflictBuffs(template.useBuffType, accuracy, false, template.removeBuff);

                    if (target.parent != null && template.hitEffect != null)
                    {
                        Finder.fx.SpawnEffect(target.parent.transform, template.hitEffect);
                    }

                    amount = target.InflictDamage(amount);

                    Finder.log.Add(string.Format("{0} {1} {2} {3}", target.Name, Finder.txt.actionNames.takes, amount, Finder.txt.basicVocabulary.damage));
                }
            }
        }
        // -------------------------------------------------------------------------------
        // ActionRecover
        // -------------------------------------------------------------------------------
        protected void ActionRecover(InstanceBase activator, bool targetAll = false)
        {
            int amount = 0;

            CharacterBase[] targets;

            if (targetAll)
            {
                targets = Finder.party.characters.ToArray();
            }
            else
            {
                targets = RPGHelper.getRandomPlayer();
            }

            RPGHelper.RecoverTargets(null, activator, amount, targets);
        }
        // -------------------------------------------------------------------------------
        // CanUse
        // -------------------------------------------------------------------------------
        public virtual bool CanUse(CharacterBase target)
        {
            if (useType == CanUseType.None && useLocation == CanUseLocation.None)
            {
                return(false);
            }

            if ((this is TemplateSkillSpecial || this is TemplateItemSpecial) && useEffectType == SpecialActionType.PlayerWarpDungeon)
            {
                if (Finder.party.MapExplorationInfo.GetExploredMapCount == 0)
                {
                    return(false);
                }
            }

            return(RPGHelper.getCanUseType(useType, target) && RPGHelper.getCanUseLocation(useLocation));
        }
        // -----------------------------------------------------------------------------------
        // HeroPropertyChanged
        // -----------------------------------------------------------------------------------
        void HeroPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            if (panel == null)
            {
                return;
            }

            switch (e.PropertyName)
            {
            case "LV":
                levelText.text = Finder.txt.basicDerivedStatNames.LV + character.Level.ToString();
                UpdatePortrait();
                prevLV = character.Level;
                break;

            case "HP":
                healthSlider.value = RPGHelper.getPercentageValue(character.HP, character.MaxHP);
                UpdatePortrait();
                prevHP = character.HP;
                break;

            case "MP":
                manaSlider.value = RPGHelper.getPercentageValue(character.MP, character.MaxMP);
                UpdatePortrait();
                prevMP = character.MP;
                break;

            case "AttributePoints":
                pointsImg.gameObject.SetActive(character.AttributePoints > 0);
                break;

            case "Buffs":
                UpdateBuffs();
                break;

            case "XP":
                UpdatePortrait();
                prevXP = character.XP;
                break;
            }
        }
        // -----------------------------------------------------------------------------------
        // UpdateAll
        // -----------------------------------------------------------------------------------
        public void UpdateAll(bool flashing = true)
        {
            if (character == null)
            {
                return;
            }

            prevHP = character.HP;
            prevMP = character.MP;
            prevXP = character.XP;
            prevLV = character.Level;

            UpdatePortrait(false);

            nameText.text      = character.template.fullName;
            levelText.text     = Finder.txt.basicDerivedStatNames.LV + character.Level.ToString();
            healthSlider.value = RPGHelper.getPercentageValue(character.HP, character.MaxHP);
            manaSlider.value   = RPGHelper.getPercentageValue(character.MP, character.MaxMP);
            pointsImg.gameObject.SetActive(character.AttributePoints > 0);

            UpdateBuffs();
        }
Ejemplo n.º 10
0
        // -------------------------------------------------------------------------------
        // CalculateFinalDamage
        // -------------------------------------------------------------------------------
        public static int CalculateFinalDamage(int damage, TemplateMetaCombatStyle attackType, TemplateMetaElement element, CharacterBase target, bool IsRearguard = false)
        {
            int defense = 0;

            damage = (int)(damage * RPGHelper.getElementalRelation(element, target));

            defense = target.stats.combatStyles.FirstOrDefault(x => x.template == attackType).defenseValue;

            if (IsRearguard)
            {
                damage = (int)(damage * attackType.rearAttackModifier);
            }
            else
            {
                damage = (int)(damage * attackType.frontAttackModifier);
            }

            if (target.IsRearguard)
            {
                defense = (int)(defense * attackType.rearDefenseModifier);
            }
            else
            {
                defense = (int)(defense * attackType.frontDefenseModifier);
            }

            float variance = UnityEngine.Random.Range(1 - Finder.battle.maxDamageVariation, 1 + Finder.battle.maxDamageVariation);

            damage = (int)(damage * variance);

            damage -= defense;

            if (damage <= 0)
            {
                damage = 1;
            }

            return(damage);
        }
        // -------------------------------------------------------------------------------
        // ExecuteEventActions
        // -------------------------------------------------------------------------------
        protected void ExecuteEventActions(int id)
        {
            if (currentNode.choiceActions.Length == 0 ||
                currentNode.choiceActions.Length < id ||
                currentNode.choiceActions[id] == null)
            {
                return;
            }

            bool wait = false;

            // --------------------------------------------------------------------------- Play Sound

            Finder.audio.PlaySFX(currentNode.choiceActions[id].soundEffect);

            // --------------------------------------------------------------------------- Costs

            foreach (TemplateItem tmpl in currentNode.choiceActions[id].removeItems)
            {
                Finder.party.inventory.AddItem(tmpl, -1);
            }

            foreach (TemplateCharacterHero tmpl in currentNode.choiceActions[id].removeHeroes)
            {
                Finder.party.DismissHero(tmpl);
            }

            foreach (AbilityLevel tmpl in currentNode.choiceActions[id].castAbilities)
            {
                CharacterBase target = Finder.party.HasAbility(tmpl.template, tmpl.level);
                if (target != null)
                {
                    target.MP -= tmpl.template.GetCost(tmpl.level);
                }
            }

            if (currentNode.choiceActions[id].removeCurrencyAmount != 0)
            {
                Finder.party.currencies.setResource(currentNode.choiceActions[id].currencyType, currentNode.choiceActions[id].removeCurrencyAmount * -1);
            }

            // --------------------------------------------------------------------------- Rewards

            foreach (TemplateCharacterHero tmpl in currentNode.choiceActions[id].addHeroes)
            {
                if (tmpl.checkQuantity)
                {
                    Finder.party.AddHero(tmpl);
                }
            }

            if (currentNode.choiceActions[id].addItems.Length > 0)
            {
                RPGHelper.DropLoot(currentNode.choiceActions[id].addItems.ToList());
            }

            Finder.party.AddExperience(currentNode.choiceActions[id].addExperience);

            // --------------------------------------------------------------------------- Attack Party

            if (currentNode.choiceActions[id].attackAbility != null)
            {
                bool targetAll = false;

                if (currentNode.choiceActions[id].attackTarget == InteractableEventTarget.All)
                {
                    targetAll = true;
                }

                InstanceSkill instance = new InstanceSkill(currentNode.choiceActions[id].attackAbility, currentNode.choiceActions[id].attackAbilityLevel);

                ActionDamage(instance, targetAll);
            }

            // --------------------------------------------------------------------------- Cure Party

            if (currentNode.choiceActions[id].curativeAbility != null)
            {
                bool targetAll = false;

                if (currentNode.choiceActions[id].attackTarget == InteractableEventTarget.All)
                {
                    targetAll = true;
                }

                InstanceSkill instance = new InstanceSkill(currentNode.choiceActions[id].curativeAbility, currentNode.choiceActions[id].curativeAbilityLevel);

                ActionRecover(instance, targetAll);
            }

            // --------------------------------------------------------------------------- Manipulate other Event

            foreach (InteractableEventAction tmpl in currentNode.choiceActions[id].events)
            {
                string             name = string.Format("{0}_{1}", tmpl.targetX, tmpl.targetY);
                GameObject         go   = GameObject.Find(name);
                DungeonObjectEvent co   = go.GetComponent <DungeonObjectEvent>();

                if (go == null || co == null)
                {
                    Debug.Log(string.Format("Error: No event for condition at {0}/{1}", tmpl.targetX, tmpl.targetY));
                }

                if (tmpl.targetActivation == BoolType.True)
                {
                    co.Activate();
                }
                else if (tmpl.targetActivation == BoolType.False)
                {
                    co.Deactivate();
                }

                if (tmpl.targetInteraction == BoolType.True)
                {
                    co.AddInteraction();
                }
                else if (tmpl.targetInteraction == BoolType.False)
                {
                    co.RemoveInteraction();
                }
            }

            // --------------------------------------------------------------------------- Manipulate this Event

            if (currentNode.choiceActions[id].eventActivation == BoolType.True)
            {
                Activate();
            }
            else if (currentNode.choiceActions[id].eventActivation == BoolType.False)
            {
                Deactivate();
            }

            if (currentNode.choiceActions[id].eventInteraction == BoolType.True)
            {
                AddInteraction();
            }
            else if (currentNode.choiceActions[id].eventInteraction == BoolType.False)
            {
                RemoveInteraction();
            }

            // --------------------------------------------------------------------------- Animate Event

            if (currentNode.choiceActions[id].moveDirection != MoveType.None)
            {
                moveDirection = currentNode.choiceActions[id].moveDirection;
                IsMoving      = true;
            }

            // --------------------------------------------------------------------------- Teleportation

            if (currentNode.choiceActions[id].teleport.locationType != LocationType.None)
            {
                Finder.map.TeleportPlayer(currentNode.choiceActions[id].teleport);
            }

            // --------------------------------------------------------------------------- Open Shop

            if (currentNode.choiceActions[id].openShop != null)
            {
                Finder.ui.OverrideShopState(currentNode.choiceActions[id].openShop);
                Finder.ui.PushState(UIState.ShopOutside);
            }

            // --------------------------------------------------------------------------- Start Combat

            if (currentNode.choiceActions[id].startCombat)
            {
                int  BattlePoolId         = currentNode.choiceActions[id].battlePoolId;
                int  BattleEncLevel       = currentNode.choiceActions[id].battleEncounterLevel;
                int  BattleEncAmountMin   = currentNode.choiceActions[id].battleEncounterAmountMin;
                int  BattleEncAmountMax   = currentNode.choiceActions[id].battleEncounterAmountMax;
                bool BattleEncAmountScale = currentNode.choiceActions[id].battleEncounterAmountScale;

                Finder.battle.StartBattle(BattlePoolId, BattleEncLevel, BattleEncAmountMin, BattleEncAmountMax, BattleEncAmountScale, !tile.TriggerOnce);

                wait = true;
            }

            // --------------------------------------------------------------------------- Complete Event

            StartCoroutine(WaitForCompletion(id, wait));
        }
 // -------------------------------------------------------------------------------
 // CanUse
 // -------------------------------------------------------------------------------
 public bool CanUse(CharacterBase source, int level)
 {
     return(!source.IsSilenced && !source.IsStunned && source.IsAlive && CheckCost(source, level) && level > 0 && RPGHelper.getCanUseLocation(useLocation));
 }