Exemplo n.º 1
0
        private void FindAttackTarget()
        {
            BattleCalculateManager  calculateManager  = Global.battleManager.calculateManager;
            BattleTilesManager      tilesManager      = Global.battleManager.tilesManager;
            BattleCharactersManager charactersManager = Global.charactersManager;

            attackTarget = null;
            targetTile   = null;
            if (mCharacter.currentSkill == null)
            {
                return;
            }
            float tileAid = 0;

            foreach (MCharacter character in charactersManager.mCharacters)
            {
                if (character.hp == 0 || character.isHide)
                {
                    continue;
                }
                if (charactersManager.IsSameBelong(mCharacter.belong, character.belong))
                {
                    continue;
                }
                VTile vTile = GetNearestNode(character, tilesManager.currentMovingTiles);
                //可否攻击
                bool canAttack = charactersManager.IsInSkillDistance(character.coordinate, vTile.coordinate, mCharacter);
                if (!canAttack)
                {
                    continue;
                }
                if (attackTarget == null)
                {
                    attackTarget = character;
                    targetTile   = vTile;
                    tileAid      = 0;
                    continue;
                }
                //是否可杀死
                bool aCanKill = calculateManager.Hert(mCharacter, attackTarget, targetTile) - attackTarget.hp >= 0;
                if (aCanKill)
                {
                    continue;
                }
                bool bCanKill = calculateManager.Hert(mCharacter, character, targetTile) - character.hp >= 0;
                if (!aCanKill && bCanKill)
                {
                    attackTarget = character;
                    targetTile   = vTile;
                    tileAid      = 0;
                    continue;
                }
                //是否反击
                bool aCanCounter = calculateManager.CanCounterAttack(mCharacter, attackTarget, targetTile.coordinate, attackTarget.coordinate);
                bool bCanCounter = calculateManager.CanCounterAttack(mCharacter, character, vTile.coordinate, character.coordinate);
                if (!aCanCounter && bCanCounter)
                {
                    continue;
                }
                else if (aCanCounter && !bCanCounter)
                {
                    attackTarget = character;
                    targetTile   = vTile;
                    tileAid      = 0;
                    continue;
                }
                //地形优势
                float aTileAid = tileAid;
                if (Global.IsFloatZero(aTileAid))
                {
                    aTileAid = attackTarget.TileAid(targetTile);
                }
                float bTileAid = character.TileAid(vTile);
                if (aTileAid > bTileAid)
                {
                    attackTarget = character;
                    targetTile   = vTile;
                    tileAid      = bTileAid;
                    continue;
                }
            }
        }
Exemplo n.º 2
0
        public IEnumerator Execute()
        {
            BattleCalculateManager  calculateManager  = Global.battleManager.calculateManager;
            BattleCharactersManager charactersManager = Global.charactersManager;
            TileMap mapSearch = Global.mapSearch;
            //行动顺序
            List <MCharacter> characters = charactersManager.mCharacters.FindAll((c) => {
                return(c.belong == this.belong && c.hp > 0 && !c.isHide && !c.actionOver);
            });

            characters.Sort((a, b) => {
                VTile aTile = mapSearch.GetTile(a.coordinate);
                VTile bTile = mapSearch.GetTile(b.coordinate);
                App.Model.Master.MTile aMTile = TileCacher.Instance.Get(aTile.tileId);
                App.Model.Master.MTile bMTile = TileCacher.Instance.Get(bTile.tileId);
                //恢复地形
                if (aMTile.heal > bMTile.heal)
                {
                    return(1);
                }
                else if (aMTile.heal > bMTile.heal)
                {
                    return(-1);
                }
                bool aPant = a.isPant;
                bool bPant = b.isPant;
                //残血状态
                if (aPant && !bPant)
                {
                    return(1);
                }
                else if (!aPant && bPant)
                {
                    return(-1);
                }
                bool aMagic = a.weaponType == WeaponType.magic;
                bool bMagic = b.weaponType == WeaponType.magic;
                bool aHeal  = a.canHeal;
                bool bHeal  = b.canHeal;
                //攻击型法师
                if (aMagic && !bMagic && !aHeal)
                {
                    return(1);
                }
                else if (!aMagic && bMagic && !bHeal)
                {
                    return(-1);
                }
                bool aArchery = a.isArcheryWeapon;
                bool bArchery = b.isArcheryWeapon;
                //远程类
                if (aArchery && !bArchery)
                {
                    return(1);
                }
                else if (!aArchery && bArchery)
                {
                    return(-1);
                }
                //近战类
                if (!aMagic && bMagic)
                {
                    return(1);
                }
                else if (aMagic && !bMagic)
                {
                    return(-1);
                }
                //恢复型法师
                return(0);
            });
            mCharacter = characters[0];
            Debug.LogError("mCharacter = " + mCharacter.name);
            MSkill attackSkill = System.Array.Find(mCharacter.skills, (MSkill skill) => {
                Model.Master.MSkill skillMaster = skill.master;
                return(System.Array.Exists(skillMaster.types, s => (s == SkillType.attack || s == SkillType.magic)) &&
                       System.Array.IndexOf(skillMaster.weaponTypes, mCharacter.weaponType) >= 0);
            });

            mCharacter.currentSkill = attackSkill;
            Global.battleManager.ClickNoneNode(mCharacter.coordinate);
            //VTile tile = mapSearch.GetTile(mCharacter.coordinate);
            //Global.battleManager.ClickNoneNode(tile.coordinate);
            yield return(new WaitForEndOfFrame());

            FindAttackTarget();
            Debug.LogError("targetTile=" + targetTile);
            bool canKill = false;

            if (targetTile != null)
            {
                canKill = calculateManager.Hert(mCharacter, attackTarget, targetTile) - attackTarget.hp >= 0;
            }
            Debug.LogError("canKill=" + canKill);
            if (canKill)
            {
                yield return(AppManager.CurrentScene.StartCoroutine(Attack()));
            }
            else
            {
                bool   needHeal  = false;
                MSkill healSkill = System.Array.Find(mCharacter.skills, (MSkill skill) => {
                    App.Model.Master.MSkill skillMaster = skill.master;
                    return(System.Array.Exists(skillMaster.types, s => s == SkillType.heal) &&
                           System.Array.IndexOf(skillMaster.weaponTypes, mCharacter.weaponType) >= 0);
                });
                Debug.LogError("healSkill=" + healSkill);
                if (healSkill != null)
                {
                    mCharacter.currentSkill = healSkill;
                    Global.battleManager.CharacterReturnNone();
                    Global.battleManager.ClickNoneNode(mCharacter.coordinate);
                    yield return(new WaitForEndOfFrame());

                    MCharacter healTarget = null;
                    VTile      healTile   = null;
                    FindHealTarget(out healTarget, out healTile);
                    if (healTarget != null)
                    {
                        attackTarget = healTarget;
                        targetTile   = healTile;
                        needHeal     = true;
                    }
                }
                if (needHeal)
                {
                    yield return(AppManager.CurrentScene.StartCoroutine(Heal()));

                    mCharacter.currentSkill = attackSkill;
                }
                else
                {
                    if (healSkill != null)
                    {
                        Global.battleManager.CharacterReturnNone();
                        Global.battleManager.ClickNoneNode(mCharacter.coordinate);
                        yield return(new WaitForEndOfFrame());

                        mCharacter.currentSkill = attackSkill;
                    }
                    yield return(AppManager.CurrentScene.StartCoroutine(Attack()));
                }
            }
        }