Exemple #1
0
        private void CastSkill(int _index, SuperEvent e)
        {
            if (isSilent)
            {
                return;
            }

            List <Hero2> targets = null;

            ISkillSDS skillSDS = Battle2.skillDataDic[sds.GetSkills()[_index]];

            switch (skillSDS.GetTargetType())
            {
            case SkillTargetType.SELF:

                targets = new List <Hero2>()
                {
                    this
                };

                break;

            case SkillTargetType.ALLY:

                targets = BattlePublicTools2.GetTargetHeroList(battle.mapData.neighbourPosMap, battle.heroMapDic, this, TargetType.ALLY);

                break;

            case SkillTargetType.ENEMY:

                targets = BattlePublicTools2.GetTargetHeroList(battle.mapData.neighbourPosMap, battle.heroMapDic, this, TargetType.ENEMY);

                break;

            case SkillTargetType.ALL:

                targets = BattlePublicTools2.GetTargetHeroList(battle.mapData.neighbourPosMap, battle.heroMapDic, this, TargetType.ALL);

                break;

            case SkillTargetType.TRIGGER:

                Hero2 tmpHero = e.datas[0] as Hero2;

                if (tmpHero == this)
                {
                    return;
                }

                targets = new List <Hero2>()
                {
                    tmpHero
                };

                break;
            }

            if (targets.Count == 0)
            {
                return;
            }

            switch (skillSDS.GetConditionType())
            {
            case SkillConditionType.DISTANCE_SMALLER:

                int dis = BattlePublicTools2.GetHerosDistance(battle.mapData.neighbourPosMap, pos, targets[0].pos);

                if (dis == 0 || dis >= skillSDS.GetConditionData())
                {
                    return;
                }

                break;

            case SkillConditionType.HP_BIGGER:

                if (nowHp <= skillSDS.GetConditionData())
                {
                    return;
                }

                break;

            case SkillConditionType.HP_SMALLER:

                if (nowHp >= skillSDS.GetConditionData())
                {
                    return;
                }

                break;

            case SkillConditionType.POWER_BIGGER:

                if (nowPower <= skillSDS.GetConditionData())
                {
                    return;
                }

                break;
            }

            while (targets.Count > skillSDS.GetTargetNum())
            {
                int index = (int)(battle.random.NextDouble() * targets.Count);

                targets.RemoveAt(index);
            }

            switch (skillSDS.GetEffectType())
            {
            case SkillEffectType.SILENT:

                for (int i = 0; i < targets.Count; i++)
                {
                    targets[i].ChangeSilent();
                }

                break;

            case SkillEffectType.MAX_HP_CHANGE:

                for (int i = 0; i < targets.Count; i++)
                {
                    targets[i].ChangeMaxHp(skillSDS.GetEffectData()[0]);
                }

                break;

            case SkillEffectType.DAMAGE_CHANGE:

                for (int i = 0; i < targets.Count; i++)
                {
                    targets[i].ChangeDamage(skillSDS.GetEffectData()[0]);
                }

                break;

            case SkillEffectType.POWER_CHANGE:

                for (int i = 0; i < targets.Count; i++)
                {
                    targets[i].ChangePower(skillSDS.GetEffectData()[0]);
                }

                break;

            case SkillEffectType.DO_DAMAGE:

                for (int i = 0; i < targets.Count; i++)
                {
                    targets[i].ChangeHp(skillSDS.GetEffectData()[0]);
                }

                break;

            case SkillEffectType.DO_DAMAGE_FIX:

                for (int i = 0; i < targets.Count; i++)
                {
                    int doDamage = skillSDS.GetEffectData()[0] + targets[i].sds.GetDamage() * skillSDS.GetEffectData()[1];

                    if (doDamage < 0)
                    {
                        targets[i].ChangeHp(doDamage);
                    }
                }

                break;

            case SkillEffectType.RECOVER_HP:

                for (int i = 0; i < targets.Count; i++)
                {
                    targets[i].ChangeHp(skillSDS.GetEffectData()[0]);
                }

                break;
            }
        }
Exemple #2
0
        private void DoAttackOnTurn(List <Hero2> _heros, BinaryWriter _mBw, BinaryWriter _oBw)
        {
            int allDamage = 0;

            List <Hero2>         heroList       = new List <Hero2>();
            List <List <Hero2> > heroTargetList = new List <List <Hero2> >();
            List <int>           heroDamageList = new List <int>();

            Dictionary <int, int> doRushDic = new Dictionary <int, int>();
            Dictionary <int, Dictionary <int, int> > doDamageDic = new Dictionary <int, Dictionary <int, int> >();

            //List<Hero2> dieHeroList = null;

            for (int i = 0; i < _heros.Count; i++)
            {
                Hero2 hero = _heros[i];

                if (hero.sds.GetHeroTypeSDS().GetCanAttack() && hero.damage > 0)
                {
                    List <Hero2> targetHeroList = BattlePublicTools2.GetAttackTargetHeroList(mapData.neighbourPosMap, heroMapDic, hero);

                    if (targetHeroList.Count > 0)
                    {
                        heroList.Add(hero);
                        heroTargetList.Add(targetHeroList);
                        heroDamageList.Add(hero.damage);

                        Dictionary <int, int> tmpDamageDic = new Dictionary <int, int>();

                        doDamageDic.Add(hero.pos, tmpDamageDic);

                        allDamage += hero.damage;

                        if (targetHeroList.Count == 1)
                        {
                            Hero2 targetHero = targetHeroList[0];

                            if (targetHero.nowPower > 0)
                            {
                                doRushDic.Add(hero.pos, targetHero.pos);

                                targetHero.nowPower--;
                            }
                        }
                    }
                }
            }

            while (allDamage > 0)
            {
                int tmp = (int)(random.NextDouble() * allDamage);

                int add = 0;

                for (int i = 0; i < heroList.Count; i++)
                {
                    int damage = heroDamageList[i];

                    if (damage + add > tmp)
                    {
                        Hero2        hero           = heroList[i];
                        List <Hero2> targetHeroList = heroTargetList[i];

                        allDamage--;

                        heroDamageList[i]--;

                        Hero2 beDamageHero = GetBeDamageHero(targetHeroList);

                        Dictionary <int, int> tmpDic = doDamageDic[hero.pos];

                        if (tmpDic.ContainsKey(beDamageHero.pos))
                        {
                            tmpDic[beDamageHero.pos]++;
                        }
                        else
                        {
                            tmpDic.Add(beDamageHero.pos, 1);
                        }

                        beDamageHero.nowHp--;

                        if (beDamageHero.nowHp == 0)
                        {
                            for (int m = heroList.Count - 1; m > -1; m--)
                            {
                                targetHeroList = heroTargetList[m];

                                int index = targetHeroList.IndexOf(beDamageHero);

                                if (index != -1)
                                {
                                    targetHeroList.RemoveAt(index);

                                    if (targetHeroList.Count == 0)
                                    {
                                        allDamage -= heroDamageList[m];

                                        heroList.RemoveAt(m);
                                        heroTargetList.RemoveAt(m);
                                        heroDamageList.RemoveAt(m);
                                    }
                                }
                            }

                            //if (dieHeroList == null)
                            //{
                            //    dieHeroList = new List<Hero2>();
                            //}

                            //dieHeroList.Add(beDamageHero);
                        }

                        break;
                    }
                    else
                    {
                        add += damage;
                    }
                }
            }

            //if (dieHeroList != null)
            //{
            //    for (int i = 0; i < dieHeroList.Count; i++)
            //    {
            //        Hero2 dieHero = dieHeroList[i];

            //        dieHero.Die();

            //        heroMapDic.Remove(dieHero.pos);
            //    }
            //}

            _mBw.Write(doRushDic.Count);

            _oBw.Write(doRushDic.Count);

            Dictionary <int, int> .Enumerator enumerator3 = doRushDic.GetEnumerator();

            while (enumerator3.MoveNext())
            {
                _mBw.Write(enumerator3.Current.Key);

                _oBw.Write(enumerator3.Current.Key);

                _mBw.Write(enumerator3.Current.Value);

                _oBw.Write(enumerator3.Current.Value);
            }

            _mBw.Write(doDamageDic.Count);

            _oBw.Write(doDamageDic.Count);

            Dictionary <int, Dictionary <int, int> > .Enumerator enumerator = doDamageDic.GetEnumerator();

            while (enumerator.MoveNext())
            {
                _mBw.Write(enumerator.Current.Key);

                _oBw.Write(enumerator.Current.Key);

                Dictionary <int, int> tmpDic = enumerator.Current.Value;

                _mBw.Write(tmpDic.Count);

                _oBw.Write(tmpDic.Count);

                Dictionary <int, int> .Enumerator enumerator2 = tmpDic.GetEnumerator();

                while (enumerator2.MoveNext())
                {
                    _mBw.Write(enumerator2.Current.Key);

                    _oBw.Write(enumerator2.Current.Key);

                    _mBw.Write(enumerator2.Current.Value);

                    _oBw.Write(enumerator2.Current.Value);
                }
            }
        }