Esempio n. 1
0
        private void HeroRecoverPower()
        {
            Dictionary <int, Hero2> .ValueCollection.Enumerator enumerator = heroMapDic.Values.GetEnumerator();

            while (enumerator.MoveNext())
            {
                Hero2 hero = enumerator.Current;

                hero.RefreshRoundOver();

                if (hero.nowPower < hero.sds.GetPower())
                {
                    hero.nowPower++;
                }
                else
                {
                    hero.nowHp += hero.nowPower;

                    if (hero.nowHp > hero.maxHp)
                    {
                        hero.nowHp = hero.maxHp;
                    }
                }

                //hero.isMoved = false;

                hero.isSummon = false;
            }
        }
Esempio n. 2
0
        private Hero2 GetBeDamageHero(List <Hero2> _targetHeroList)
        {
            int allHp = 0;

            for (int i = 0; i < _targetHeroList.Count; i++)
            {
                allHp += _targetHeroList[i].nowHp;
            }

            int damage = (int)(random.NextDouble() * allHp);

            int add = 0;

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

                if (hero.nowHp + add > damage)
                {
                    return(hero);
                }
                else
                {
                    add += hero.nowHp;
                }
            }

            return(null);
        }
Esempio n. 3
0
        private void DoAttack(BinaryWriter _mBw, BinaryWriter _oBw)
        {
            Dictionary <int, int> attackedHeroDic = new Dictionary <int, int>();

            for (int i = MAX_POWER; i > 0; i--)
            {
                List <Hero2> heros = new List <Hero2>();

                Dictionary <int, Hero2> .ValueCollection.Enumerator enumerator = heroMapDic.Values.GetEnumerator();

                while (enumerator.MoveNext())
                {
                    Hero2 hero = enumerator.Current;

                    if (!hero.isSummon && hero.nowPower >= i)
                    {
                        if (!attackedHeroDic.ContainsKey(hero.pos))
                        {
                            heros.Add(hero);

                            attackedHeroDic.Add(hero.pos, 1);
                        }
                        else
                        {
                            int attackTimes = attackedHeroDic[hero.pos];

                            if (hero.sds.GetAttackTimes() > attackTimes)
                            {
                                heros.Add(hero);

                                attackedHeroDic[hero.pos] = attackTimes + 1;
                            }
                        }
                    }
                }

                if (heros.Count > 0)
                {
                    _mBw.Write(true);

                    _oBw.Write(true);

                    CastSkill(heros);

                    DoAttackOnTurn(heros, _mBw, _oBw);

                    AttackOver(heros);
                }
                else
                {
                    _mBw.Write(false);

                    _oBw.Write(false);
                }
            }
        }
Esempio n. 4
0
        private void AttackOver(List <Hero2> _heros)
        {
            for (int i = 0; i < _heros.Count; i++)
            {
                string eventName = string.Format("{0}{1}", SkillEventName.ATTACKOVER, _heros[i].uid);

                SuperEvent e = new SuperEvent(eventName);

                superEventListener.DispatchEvent(e);

                eventName = string.Format("{0}{1}", SkillEventName.ATTACKOVER, _heros[i].isMine);

                e = new SuperEvent(eventName, _heros[i]);

                superEventListener.DispatchEvent(e);

                eventName = SkillEventName.ATTACKOVER.ToString();

                e = new SuperEvent(eventName, _heros[i]);

                superEventListener.DispatchEvent(e);
            }

            List <Hero2> dieHeroList = null;

            Dictionary <int, Hero2> .ValueCollection.Enumerator enumerator = heroMapDic.Values.GetEnumerator();

            while (enumerator.MoveNext())
            {
                enumerator.Current.RefreshData();

                if (enumerator.Current.nowHp < 1)
                {
                    if (dieHeroList == null)
                    {
                        dieHeroList = new List <Hero2>();
                    }

                    dieHeroList.Add(enumerator.Current);
                }
            }

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

                    dieHero.Die();

                    _heros.Remove(dieHero);

                    heroMapDic.Remove(dieHero.pos);
                }
            }
        }
Esempio n. 5
0
        private static void DoMove(Battle2 _battle, Random _random, Dictionary <Hero2, List <int> > _myHeros)
        {
            int index = (int)(_random.NextDouble() * _myHeros.Count);

            Dictionary <Hero2, List <int> > .Enumerator enumerator = _myHeros.GetEnumerator();

            for (int i = 0; i <= index; i++)
            {
                enumerator.MoveNext();
            }

            Hero2 hero = enumerator.Current.Key;

            List <int> directions = enumerator.Current.Value;

            index = (int)(_random.NextDouble() * directions.Count);

            int direction = directions[index];

            _battle.ServerDoMove(hero.pos, direction);
        }
Esempio n. 6
0
        private void DoMove(int _pos, int _direction)
        {
            Hero2 hero = heroMapDic[_pos];

            int targetPos = mapData.neighbourPosMap[_pos][_direction];

            heroMapDic.Remove(_pos);

            heroMapDic.Add(targetPos, hero);

            hero.pos = targetPos;

            hero.nowPower--;

            //hero.isMoved = true;

            if (mapDic[targetPos] != hero.isMine)
            {
                mapDic[targetPos] = hero.isMine;

                if (hero.isMine)
                {
                    mScore++;
                    oScore--;
                }
                else
                {
                    oScore++;
                    mScore--;
                }
            }

            isSkip = false;

            isMineAction = !isMineAction;
        }
Esempio n. 7
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;
            }
        }
Esempio n. 8
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);
                }
            }
        }
Esempio n. 9
0
        private void AddHero(bool _isMine, int _id, int _pos, int _nowHp, int _nowPower, bool _isSummon)
        {
            Hero2 hero = new Hero2(_isMine, _id, heroDataDic[_id], _pos, _nowHp, _nowPower, _isSummon);

            heroMapDic.Add(_pos, hero);
        }
Esempio n. 10
0
        private void AddHero(int _uid, bool _isMine, int _id, IHeroSDS _sds, int _pos)
        {
            Hero2 hero = new Hero2(this, _uid, _isMine, _id, _sds, _pos);

            heroMapDic.Add(hero.pos, hero);
        }
Esempio n. 11
0
        internal void ServerDoMove(int _pos, int _direction)
        {
            if (!heroMapDic.ContainsKey(_pos))
            {
                return;
            }

            Hero2 hero = heroMapDic[_pos];

            if (hero.isMine != isMineAction)
            {
                Log.Write("ServerDoMove  违规操作1");

                return;
            }

            if (hero.nowPower < 1 || hero.isSummon)
            {
                Log.Write("ServerDoMove  违规操作2");

                return;
            }

            if (_direction < 0 || _direction > 6)
            {
                Log.Write("ServerDoMove  违规操作3");

                return;
            }

            int targetPos = mapData.neighbourPosMap[_pos][_direction];

            if (targetPos == -1)
            {
                Log.Write("ServerDoMove  违规操作4");

                return;
            }

            if (heroMapDic.ContainsKey(targetPos))
            {
                Log.Write("ServerDoMove  违规操作5");

                return;
            }

            DoMove(_pos, _direction);

            using (MemoryStream ms = new MemoryStream())
            {
                using (BinaryWriter bw = new BinaryWriter(ms))
                {
                    bw.Write(PackageTag.S2C_DOACTION);

                    bw.Write((int)ActionType.MOVE);

                    bw.Write(_pos);

                    bw.Write(_direction);

                    serverSendDataCallBack(true, ms);

                    if (!isVsAi)
                    {
                        serverSendDataCallBack(false, ms);
                    }
                    else
                    {
                        if (!isMineAction)
                        {
                            BattleAi2.Action(this);
                        }
                    }
                }
            }
        }
Esempio n. 12
0
        private void ServerRefreshData(bool _isMine)
        {
            using (MemoryStream ms = new MemoryStream())
            {
                using (BinaryWriter bw = new BinaryWriter(ms))
                {
                    Log.Write("ServerRefreshData  isMine:" + _isMine);

                    bw.Write(PackageTag.S2C_REFRESH);

                    bw.Write(_isMine);

                    bw.Write(isMineAction);

                    bw.Write(isSkip);

                    bw.Write(mScore);

                    bw.Write(oScore);

                    bw.Write(mapData.id);

                    bw.Write(mapDic.Count);

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

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

                        bw.Write(enumerator.Current.Value);
                    }

                    bw.Write(heroMapDic.Count);

                    Dictionary <int, Hero2> .ValueCollection.Enumerator enumerator3 = heroMapDic.Values.GetEnumerator();

                    while (enumerator3.MoveNext())
                    {
                        Hero2 hero = enumerator3.Current;

                        bw.Write(hero.id);

                        bw.Write(hero.isMine);

                        bw.Write(hero.pos);

                        bw.Write(hero.nowHp);

                        bw.Write(hero.nowPower);

                        //bw.Write(hero.isMoved);

                        bw.Write(hero.isSummon);
                    }

                    Dictionary <int, int> handCards = _isMine ? mHandCards : oHandCards;

                    bw.Write(handCards.Count);

                    Dictionary <int, int> .Enumerator enumerator4 = handCards.GetEnumerator();

                    while (enumerator4.MoveNext())
                    {
                        bw.Write(enumerator4.Current.Key);

                        bw.Write(enumerator4.Current.Value);
                    }

                    int oppHandCardsNum = _isMine ? oHandCards.Count : mHandCards.Count;

                    bw.Write(oppHandCardsNum);

                    bw.Write(mMoney);

                    bw.Write(oMoney);

                    serverSendDataCallBack(_isMine, ms);
                }
            }
        }
Esempio n. 13
0
        public IEnumerator ClientDoAttack(BinaryReader _br)
        {
            isSkip = false;

            //isMineAction = !isMineAction;//设置行动顺序

            for (int i = MAX_POWER; i > 0; i--)
            {
                bool b = _br.ReadBoolean();

                if (b)
                {
                    yield return(i);

                    int num = _br.ReadInt32();

                    for (int m = 0; m < num; m++)
                    {
                        int pos = _br.ReadInt32();

                        int targetPos = _br.ReadInt32();

                        Hero2 targetHero = heroMapDic[targetPos];

                        if (targetHero.nowPower > 0)
                        {
                            targetHero.nowPower--;
                        }

                        yield return(new KeyValuePair <int, int>(pos, targetPos));
                    }

                    num = _br.ReadInt32();

                    for (int m = 0; m < num; m++)
                    {
                        int pos = _br.ReadInt32();

                        int targetNum = _br.ReadInt32();

                        if (targetNum > 0)
                        {
                            KeyValuePair <int, int>[] pair2 = new KeyValuePair <int, int> [targetNum];

                            KeyValuePair <int, KeyValuePair <int, int>[]> pair = new KeyValuePair <int, KeyValuePair <int, int>[]>(pos, pair2);

                            for (int n = 0; n < targetNum; n++)
                            {
                                int targetPos = _br.ReadInt32();

                                int damage = _br.ReadInt32();

                                heroMapDic[targetPos].nowHp -= damage;

                                pair2[n] = new KeyValuePair <int, int>(targetPos, damage);
                            }

                            yield return(pair);
                        }
                    }

                    List <int> delList = null;

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

                    while (enumerator3.MoveNext())
                    {
                        if (enumerator3.Current.Value.nowHp == 0)
                        {
                            if (delList == null)
                            {
                                delList = new List <int>();
                            }

                            delList.Add(enumerator3.Current.Key);
                        }
                    }

                    if (delList != null)
                    {
                        for (int m = 0; m < delList.Count; m++)
                        {
                            heroMapDic.Remove(delList[m]);
                        }
                    }
                }
            }
        }
Esempio n. 14
0
        public static void Action(Battle2 _battle)
        {
            Random random = new Random();

            bool canMove;

            bool canSummon = false;

            Dictionary <Hero2, List <int> > myHeros = new Dictionary <Hero2, List <int> >();

            Dictionary <int, Hero2> .ValueCollection.Enumerator enumerator = _battle.heroMapDic.Values.GetEnumerator();

            while (enumerator.MoveNext())
            {
                Hero2 hero = enumerator.Current;

                if (!hero.isMine && !hero.isSummon && hero.nowPower > 0)
                {
                    List <int> tmpList = new List <int>();

                    int[] tmpArr = _battle.mapData.neighbourPosMap[hero.pos];

                    for (int i = 0; i < 6; i++)
                    {
                        if (tmpArr[i] != -1)
                        {
                            if (!_battle.heroMapDic.ContainsKey(tmpArr[i]))
                            {
                                tmpList.Add(i);
                            }
                        }
                    }

                    if (tmpList.Count > 0)
                    {
                        myHeros.Add(hero, tmpList);
                    }
                }
            }

            canMove = myHeros.Count > 0;

            List <int> summonPosList = new List <int>();

            Dictionary <int, IHeroSDS> myCards = new Dictionary <int, IHeroSDS>();

            Dictionary <int, bool> .Enumerator enumerator3 = _battle.mapDic.GetEnumerator();

            while (enumerator3.MoveNext())
            {
                if (!enumerator3.Current.Value)
                {
                    int pos = enumerator3.Current.Key;

                    if (!_battle.heroMapDic.ContainsKey(pos))
                    {
                        summonPosList.Add(pos);
                    }
                }
            }

            if (summonPosList.Count > 0)
            {
                Dictionary <int, int> .Enumerator enumerator2 = _battle.oHandCards.GetEnumerator();

                while (enumerator2.MoveNext())
                {
                    int uid = enumerator2.Current.Key;

                    int id = enumerator2.Current.Value;

                    IHeroSDS hero = Battle2.heroDataDic[id];

                    if (hero.GetCost() <= _battle.oMoney)
                    {
                        myCards.Add(uid, hero);
                    }
                }

                canSummon = myCards.Count > 0;
            }

            if (canSummon && canMove)
            {
                double r = random.NextDouble();

                if (r < 1 / 3)
                {
                    DoSummon(_battle, random, summonPosList, myCards);
                }
                else if (r < 2 * 3)
                {
                    DoMove(_battle, random, myHeros);
                }
                else
                {
                    _battle.ServerDoSkip();
                }
            }
            else if (canSummon)
            {
                double r = random.NextDouble();

                if (r < 0.5)
                {
                    DoSummon(_battle, random, summonPosList, myCards);
                }
                else
                {
                    _battle.ServerDoSkip();
                }
            }
            else if (canMove)
            {
                double r = random.NextDouble();

                if (r < 0.5)
                {
                    DoMove(_battle, random, myHeros);
                }
                else
                {
                    _battle.ServerDoSkip();
                }
            }
            else
            {
                _battle.ServerDoSkip();
            }
        }