Ejemplo n.º 1
0
        internal Hero(Battle _battle, bool _isMine, IHeroSDS _sds, int _pos, int _uid)
        {
            eventListenerV = _battle.eventListenerV;

            isMine = _isMine;

            sds = _sds;

            PosChange(_pos);

            uid = _uid;

            nowHp = sds.GetHp();

            nowPower = sds.GetPower();

            action = HeroAction.NULL;

            if (sds.GetSkills().Length > 0)
            {
                HeroSkill.Init(_battle, this);
            }

            if (sds.GetAuras().Length > 0)
            {
                HeroAura.Init(_battle, this);
            }
        }
Ejemplo n.º 2
0
        internal void ServerDoSummon(int _tmpCardUid, int _pos)
        {
            Dictionary <int, int> handCards = isMineAction ? mHandCards : oHandCards;

            if (!mapDic.ContainsKey(_pos) || mapDic[_pos] != isMineAction || !handCards.ContainsKey(_tmpCardUid))
            {
                Log.Write("ServerDoSummon  违规操作  uid:" + _tmpCardUid + "  pos:" + _pos);

                return;
            }

            int cardID = handCards[_tmpCardUid];

            IHeroSDS heroSDS = heroDataDic[cardID];

            if (heroSDS.GetCost() > (isMineAction ? mMoney : oMoney))
            {
                Log.Write("ServerDoSummon  违规操作  oMoney:" + oMoney);

                return;
            }

            handCards.Remove(_tmpCardUid);

            DoSummon(cardID, _pos);

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

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

                    bw.Write(cardID);

                    bw.Write(_pos);

                    serverSendDataCallBack(true, ms);

                    if (!isVsAi)
                    {
                        serverSendDataCallBack(false, ms);
                    }
                    else
                    {
                        if (!isMineAction)
                        {
                            BattleAi2.Action(this);
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public Hero(bool _isMine, int _id, IHeroSDS _sds, int _pos, int _nowHp, int _nowPower, bool _canMove)
        {
            isMine   = _isMine;
            id       = _id;
            sds      = _sds;
            pos      = _pos;
            nowHp    = _nowHp;
            nowPower = _nowPower;

            canMove  = _canMove;
            isSummon = false;
        }
Ejemplo n.º 4
0
        public Hero(bool _isMine, int _id, IHeroSDS _sds, int _pos)
        {
            isMine   = _isMine;
            id       = _id;
            sds      = _sds;
            pos      = _pos;
            nowHp    = sds.GetHp();
            nowPower = sds.GetPower();

            canMove  = false;
            isSummon = true;
        }
Ejemplo n.º 5
0
        public Hero2(bool _isMine, int _id, IHeroSDS _sds, int _pos, int _nowHp, int _nowPower, bool _isSummon)
        {
            isMine   = _isMine;
            id       = _id;
            sds      = _sds;
            pos      = _pos;
            nowHp    = _nowHp;
            nowPower = _nowPower;

            //isMoved = _isMoved;
            isSummon = _isSummon;
        }
Ejemplo n.º 6
0
        //为了DamageCalculator才设置为public
        public Hero(bool _isMine, IHeroSDS _sds, int _pos, int _nowHp, int _nowPower)
        {
            isMine = _isMine;

            sds = _sds;

            PosChange(_pos);

            nowHp = _nowHp;

            nowPower = _nowPower;

            action = HeroAction.NULL;
        }
Ejemplo n.º 7
0
        internal Hero(bool _isMine, IHeroSDS _sds, int _pos)
        {
            isMine = _isMine;

            sds = _sds;

            PosChange(_pos);

            nowHp = sds.GetHp();

            nowPower = sds.GetPower();

            action = HeroAction.NULL;
        }
Ejemplo n.º 8
0
        internal void Init(bool _isMine, IHeroSDS _sds, int _x, int _y, int _nowHp)
        {
            isMine = _isMine;

            fix = isMine ? 1 : -1;

            sds = _sds;

            x = _x;

            y = _y;

            nowHp = _nowHp;

            moveNum = sds.GetMove();
        }
Ejemplo n.º 9
0
        internal void Init(bool _isMine, IHeroSDS _sds, int _x)
        {
            isMine = _isMine;

            fix = isMine ? 1 : -1;

            sds = _sds;

            x = _x;

            y = isMine ? 0 : BattleConst.mapWidth - 1;

            nowHp = _sds.GetHp();

            moveNum = sds.GetMove();
        }
Ejemplo n.º 10
0
        public int ClientDoSummonOppHero(BinaryReader _br)
        {
            int summonNum = _br.ReadInt32();

            if (summonNum > 0)
            {
                for (int i = 0; i < summonNum; i++)
                {
                    int pos = _br.ReadInt32();

                    int heroID = _br.ReadInt32();

                    IHeroSDS sds = heroDataDic[heroID];

                    AddHero(!clientIsMine, heroID, sds, pos);
                }
            }

            return(summonNum);
        }
Ejemplo n.º 11
0
        public int ClientDoSummonMyHero(BinaryReader _br)
        {
            Dictionary <int, int> summonAction = clientIsMine ? mSummonAction : oSummonAction;

            int summonNum = summonAction.Count;

            if (summonNum > 0)
            {
                Dictionary <int, int> tmpCards = clientIsMine ? mHandCards : oHandCards;

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

                while (enumerator.MoveNext())
                {
                    int tmpCardUid = enumerator.Current.Key;

                    int pos = enumerator.Current.Value;

                    int heroID = tmpCards[tmpCardUid];

                    IHeroSDS sds = heroDataDic[heroID];

                    if (clientIsMine)
                    {
                        mMoney -= sds.GetCost();
                    }
                    else
                    {
                        oMoney -= sds.GetCost();
                    }

                    tmpCards.Remove(tmpCardUid);

                    AddHero(clientIsMine, heroID, sds, pos);
                }

                summonAction.Clear();
            }

            return(summonNum);
        }
Ejemplo n.º 12
0
        private void DoSummon(int _cardID, int _pos)
        {
            IHeroSDS heroSDS = heroDataDic[_cardID];

            if (isMineAction)
            {
                mMoney -= heroSDS.GetCost();
            }
            else
            {
                oMoney -= heroSDS.GetCost();
            }

            AddHero(heroUid, isMineAction, _cardID, heroSDS, _pos);

            heroUid++;

            isSkip = false;

            isMineAction = !isMineAction;
        }
Ejemplo n.º 13
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();
            }
        }
Ejemplo n.º 14
0
        private void DoSummonAction(BinaryWriter _mBw, BinaryWriter _oBw)
        {
            _oBw.Write(mSummonAction.Count);

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

            while (enumerator.MoveNext())
            {
                int tmpCardUid = enumerator.Current.Key;
                int pos        = enumerator.Current.Value;

                _oBw.Write(pos);

                if (mapDic.ContainsKey(pos) && mapDic[pos] && !mapBelongDic.ContainsKey(pos) && !heroMapDic.ContainsKey(pos))
                {
                    int heroID = mHandCards[tmpCardUid];

                    _oBw.Write(heroID);

                    IHeroSDS sds = heroDataDic[heroID];

                    if (sds.GetCost() > mMoney)
                    {
                        throw new Exception("b");
                    }
                    else
                    {
                        mMoney -= sds.GetCost();
                    }

                    mHandCards.Remove(tmpCardUid);

                    AddHero(true, heroID, sds, pos);
                }
                else
                {
                    throw new Exception("d");
                }
            }

            mSummonAction.Clear();

            _mBw.Write(oSummonAction.Count);

            enumerator = oSummonAction.GetEnumerator();

            while (enumerator.MoveNext())
            {
                int uid = enumerator.Current.Key;
                int pos = enumerator.Current.Value;

                _mBw.Write(pos);

                if (mapDic.ContainsKey(pos) && !mapDic[pos] && !mapBelongDic.ContainsKey(pos) && !heroMapDic.ContainsKey(pos))
                {
                    int heroID = oHandCards[uid];

                    _mBw.Write(heroID);

                    IHeroSDS sds = heroDataDic[heroID];

                    if (sds.GetCost() > oMoney)
                    {
                        throw new Exception("b");
                    }
                    else
                    {
                        oMoney -= sds.GetCost();
                    }

                    oHandCards.Remove(uid);

                    AddHero(false, heroID, sds, pos);
                }
                else
                {
                    throw new Exception("d");
                }
            }

            oSummonAction.Clear();
        }
Ejemplo n.º 15
0
        private void AddHero(bool _isMine, int _id, IHeroSDS _sds, int _pos)
        {
            Hero hero = new Hero(_isMine, _id, _sds, _pos);

            heroMapDic.Add(hero.pos, hero);
        }
Ejemplo n.º 16
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);
        }
Ejemplo n.º 17
0
        private static void DoSummon(Battle _battle, bool _isMine, double _wrongValue)
        {
            //---summon
            int money;
            Dictionary <int, int> handCards;
            int oppBasePos;

            if (_isMine)
            {
                oppBasePos = _battle.mapData.oBase;
                money      = _battle.mMoney;
                handCards  = _battle.mHandCards;
            }
            else
            {
                oppBasePos = _battle.mapData.mBase;
                money      = _battle.oMoney;
                handCards  = _battle.oHandCards;
            }

            List <int>    cards       = new List <int>();
            List <double> randomList2 = new List <double>();

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

            while (enumerator4.MoveNext())
            {
                KeyValuePair <int, int> pair = enumerator4.Current;

                int cardID = pair.Value;

                IHeroSDS heroSDS = Battle.GetHeroData(cardID);

                if (heroSDS.GetCost() <= money)
                {
                    cards.Add(pair.Key);

                    randomList2.Add(1);
                }
            }

            if (cards.Count > 0)
            {
                List <int> resultList = new List <int>();

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

                List <int> nowCheckPos = new List <int>()
                {
                    oppBasePos
                };

                Dictionary <int, bool> checkedPos = new Dictionary <int, bool>();

                checkedPos.Add(oppBasePos, false);

                while (nowCheckPos.Count > 0)
                {
                    int nowPos = nowCheckPos[0];

                    nowCheckPos.RemoveAt(0);

                    List <int> posList = BattlePublicTools.GetNeighbourPos(_battle.mapData.neighbourPosMap, nowPos);

                    for (int i = 0; i < posList.Count; i++)
                    {
                        int pos = posList[i];

                        if (!checkedPos.ContainsKey(pos))
                        {
                            checkedPos.Add(pos, false);

                            bool b = _battle.GetPosIsMine(pos);

                            if (b == _isMine)
                            {
                                if (!_battle.heroMapDic.ContainsKey(pos))
                                {
                                    resultList.Add(pos);
                                }
                            }
                            else
                            {
                                nowCheckPos.Add(pos);
                            }
                        }
                    }
                }

                for (int i = 0; i < resultList.Count; i++)
                {
                    int nowPos = resultList[i];

                    List <int> posList = BattlePublicTools.GetNeighbourPos(_battle.mapData.neighbourPosMap, nowPos);

                    for (int m = 0; m < posList.Count; m++)
                    {
                        int pos = posList[m];

                        if (!_battle.heroMapDic.ContainsKey(pos) && !resultList.Contains(pos) && !resultList2.Contains(pos))
                        {
                            bool b = _battle.GetPosIsMine(pos);

                            if (b == _isMine)
                            {
                                resultList2.Add(pos);
                            }
                        }
                    }
                }

                PublicTools.ShuffleList(cards, Battle.random);

                while (Battle.random.NextDouble() < 0.8 && cards.Count > 0 && (resultList.Count > 0 || resultList2.Count > 0))
                {
                    int cardUid = cards[0];

                    cards.RemoveAt(0);

                    randomList2.RemoveAt(0);

                    int cardID = handCards[cardUid];

                    IHeroSDS heroSDS = Battle.GetHeroData(cardID);

                    if (heroSDS.GetCost() <= money)
                    {
                        List <int> summonPosList;

                        if (resultList.Count > 0 && resultList2.Count > 0)
                        {
                            if (Battle.random.NextDouble() < 0.6)
                            {
                                summonPosList = resultList;
                            }
                            else
                            {
                                summonPosList = resultList2;
                            }
                        }
                        else if (resultList.Count > 0)
                        {
                            summonPosList = resultList;
                        }
                        else
                        {
                            summonPosList = resultList2;
                        }

                        int index = (int)(Battle.random.NextDouble() * summonPosList.Count);

                        int summonPos = summonPosList[index];

                        summonPosList.RemoveAt(index);

                        _battle.summon.Add(cardUid, summonPos);

                        money -= heroSDS.GetCost();
                    }
                    else
                    {
                        break;
                    }
                }
            }
        }
Ejemplo n.º 18
0
        public Hero2(Battle2 _battle, int _uid, bool _isMine, int _id, IHeroSDS _sds, int _pos)
        {
            battle = _battle;

            uid = _uid;

            isMine   = _isMine;
            id       = _id;
            sds      = _sds;
            pos      = _pos;
            maxHp    = nowHp = sds.GetHp();
            damage   = sds.GetDamage();
            nowPower = sds.GetPower();

            //isMoved = false;

            isSummon = !sds.GetHeroTypeSDS().GetCanCharge();

            eventIndexList = new List <int>();

            for (int i = 0; i < sds.GetSkills().Length; i++)
            {
                ISkillSDS skillSDS = Battle2.skillDataDic[sds.GetSkills()[i]];

                int index = i;

                Action <SuperEvent> del = delegate(SuperEvent e)
                {
                    CastSkill(index, e);
                };

                switch (skillSDS.GetTrigger())
                {
                case SkillTrigger.ALL:

                    int eventIndex = battle.superEventListener.AddListener(skillSDS.GetEventName().ToString(), del);

                    eventIndexList.Add(eventIndex);

                    break;

                case SkillTrigger.HERO:

                    eventIndex = battle.superEventListener.AddListener(string.Format("{0}{1}", skillSDS.GetEventName(), uid), del);

                    eventIndexList.Add(eventIndex);

                    break;

                case SkillTrigger.ALLY:

                    eventIndex = battle.superEventListener.AddListener(string.Format("{0}{1}", skillSDS.GetEventName(), isMine), del);

                    eventIndexList.Add(eventIndex);

                    break;

                case SkillTrigger.ENEMY:

                    eventIndex = battle.superEventListener.AddListener(string.Format("{0}{1}", skillSDS.GetEventName(), !isMine), del);

                    eventIndexList.Add(eventIndex);

                    break;
                }
            }
        }