예제 #1
0
파일: Battle.cs 프로젝트: ludidilu/War_lib
    public void ClientSendUnitCommand(int _id)
    {
        UnitCommandData data = new UnitCommandData(true, _id);

        ClientSendCommand(data);
    }
예제 #2
0
파일: Battle.cs 프로젝트: ludidilu/War_lib
    public void ServerRefresh(bool _isMine)
    {
        Log.Print("ServerRefresh:" + roundNum + "   isMine:" + _isMine);

        using (MemoryStream ms = new MemoryStream())
        {
            using (BinaryWriter bw = new BinaryWriter(ms))
            {
                bw.Write((int)S2CCommand.REFRESH);

                bw.Write(_isMine);

                bw.Write(roundNum);

                bw.Write(uid);

                if (_isMine)
                {
                    bw.Write(mMoney);

                    bw.Write(oShowMoney);
                }
                else
                {
                    bw.Write(mShowMoney);

                    bw.Write(oMoney);
                }

                bw.Write(unitList.Count);

                LinkedList <Unit> .Enumerator enumerator = unitList.GetEnumerator();

                while (enumerator.MoveNext())
                {
                    Unit unit = enumerator.Current;

                    unit.WriteData(bw);
                }

                bw.Write(skillList.Count);

                LinkedList <Skill> .Enumerator enumerator7 = skillList.GetEnumerator();

                while (enumerator7.MoveNext())
                {
                    Skill skill = enumerator7.Current;

                    skill.WriteData(bw);
                }

                bw.Write(mUnitPool.Count);

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

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

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

                bw.Write(oUnitPool.Count);

                enumerator2 = oUnitPool.GetEnumerator();

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

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

                bw.Write(commandPool.Count);

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

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

                    Dictionary <int, CommandData> tmpDic = enumerator3.Current.Value;

                    bw.Write(tmpDic.Count);

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

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

                        CommandData data = enumerator4.Current.Value;

                        bw.Write(data.isMine);

                        if (data is UnitCommandData)
                        {
                            UnitCommandData command = data as UnitCommandData;

                            bw.Write((int)CommandType.UNIT);

                            bw.Write(command.id);
                        }
                        else if (data is HeroCommandData)
                        {
                            HeroCommandData command = data as HeroCommandData;

                            bw.Write((int)CommandType.HERO);

                            bw.Write(command.id);

                            bw.Write(command.pos.x);

                            bw.Write(command.pos.y);
                        }
                        else if (data is SkillCommandData)
                        {
                            SkillCommandData command = data as SkillCommandData;

                            bw.Write((int)CommandType.SKILL);

                            bw.Write(command.id);

                            bw.Write(command.pos.x);

                            bw.Write(command.pos.y);
                        }
                    }
                }

                Dictionary <int, Dictionary <int, UnitCommandData> > unitCommandData = _isMine ? mUnitCommandPool : oUnitCommandPool;

                bw.Write(unitCommandData.Count);

                Dictionary <int, Dictionary <int, UnitCommandData> > .Enumerator enumerator5 = unitCommandData.GetEnumerator();

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

                    Dictionary <int, UnitCommandData> tmpDic = enumerator5.Current.Value;

                    bw.Write(tmpDic.Count);

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

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

                        bw.Write(enumerator6.Current.Value.id);
                    }
                }

                serverSendDataCallBack(_isMine, ms);
            }
        }
    }
예제 #3
0
파일: Battle.cs 프로젝트: ludidilu/War_lib
    private void ClientRefresh(BinaryReader _br)
    {
        unitDic.Clear();

        unitList.Clear();

        mUnitPool.Clear();

        oUnitPool.Clear();

        commandPool.Clear();

        mHeroCommandPool.Clear();

        oHeroCommandPool.Clear();

        mSkillCommandPool.Clear();

        oSkillCommandPool.Clear();

        skillList.Clear();

        mHeroPool.Clear();

        oHeroPool.Clear();

        mUnitCommandPool.Clear();

        oUnitCommandPool.Clear();

        simulator.ClearAgents();

        clientIsMine = _br.ReadBoolean();

        serverRoundNum = roundNum = _br.ReadInt32();

        Log.Print("client refresh data " + roundNum + "  clientIsMine:" + clientIsMine);

        uid = _br.ReadInt32();

        mMoney = _br.ReadInt32();

        oMoney = _br.ReadInt32();

        int num = _br.ReadInt32();

        for (int i = 0; i < num; i++)
        {
            Unit unit = new Unit();

            unit.Init(this, simulator, _br);

            unitDic.Add(unit.uid, unit);

            unitList.AddLast(unit);

            if (unit.sds.GetIsHero())
            {
                Dictionary <int, Unit> tmpDic = unit.isMine ? mHeroPool : oHeroPool;

                tmpDic.Add(unit.id, unit);
            }
        }

        num = _br.ReadInt32();

        for (int i = 0; i < num; i++)
        {
            Skill skill = new Skill();

            skill.Init(this, simulator, _br);

            skillList.AddLast(skill);
        }

        num = _br.ReadInt32();

        for (int i = 0; i < num; i++)
        {
            int id = _br.ReadInt32();

            int num2 = _br.ReadInt32();

            mUnitPool.Add(id, num2);
        }

        num = _br.ReadInt32();

        for (int i = 0; i < num; i++)
        {
            int id = _br.ReadInt32();

            int num2 = _br.ReadInt32();

            oUnitPool.Add(id, num2);
        }

        num = _br.ReadInt32();

        for (int i = 0; i < num; i++)
        {
            int tmpRoundNum = _br.ReadInt32();

            int num2 = _br.ReadInt32();

            Dictionary <int, CommandData> tmpDic = new Dictionary <int, CommandData>();

            commandPool.Add(tmpRoundNum, tmpDic);

            for (int m = 0; m < num2; m++)
            {
                int tmpCommandID = _br.ReadInt32();

                bool isMine = _br.ReadBoolean();

                CommandData commandData;

                CommandType commandType = (CommandType)_br.ReadInt32();

                switch (commandType)
                {
                case CommandType.UNIT:

                    int id = _br.ReadInt32();

                    commandData = new UnitCommandData(isMine, id);

                    break;

                case CommandType.HERO:

                    id = _br.ReadInt32();

                    double x = _br.ReadDouble();

                    double y = _br.ReadDouble();

                    commandData = new HeroCommandData(isMine, id, new Vector2(x, y));

                    Dictionary <int, HeroCommandData> tmpDic2 = isMine ? mHeroCommandPool : oHeroCommandPool;

                    tmpDic2.Add(id, commandData as HeroCommandData);

                    break;

                case CommandType.SKILL:

                    id = _br.ReadInt32();

                    x = _br.ReadDouble();

                    y = _br.ReadDouble();

                    commandData = new SkillCommandData(isMine, id, new Vector2(x, y));

                    Dictionary <int, SkillCommandData> tmpDic3 = isMine ? mSkillCommandPool : oSkillCommandPool;

                    tmpDic3.Add(id, commandData as SkillCommandData);

                    break;

                default:

                    throw new Exception("commandtype error");
                }

                tmpDic.Add(tmpCommandID, commandData);
            }
        }

        num = _br.ReadInt32();

        Dictionary <int, Dictionary <int, UnitCommandData> > unitCommandData = clientIsMine ? mUnitCommandPool : oUnitCommandPool;

        for (int i = 0; i < num; i++)
        {
            int tmpRoundNum = _br.ReadInt32();

            int num2 = _br.ReadInt32();

            Dictionary <int, UnitCommandData> tmpDic = new Dictionary <int, UnitCommandData>();

            unitCommandData.Add(tmpRoundNum, tmpDic);

            for (int m = 0; m < num2; m++)
            {
                int tmpCommandID = _br.ReadInt32();

                int id = _br.ReadInt32();

                tmpDic.Add(tmpCommandID, new UnitCommandData(clientIsMine, id));
            }
        }

        updateCallBack(null);
    }
예제 #4
0
파일: Battle.cs 프로젝트: ludidilu/War_lib
    private bool ReceiveCommand(int _roundNum, int _commandID, CommandData _commandData)
    {
        if (_commandData is UnitCommandData)
        {
            UnitCommandData command = _commandData as UnitCommandData;

            IUnitSDS sds = getUnitCallBack(command.id);

            if (!sds.GetIsHero())
            {
                if (command.isMine)
                {
                    if (sds.GetPrize() > mMoney)
                    {
                        return(false);
                    }
                    else
                    {
                        mMoney -= sds.GetPrize();
                    }
                }
                else
                {
                    if (sds.GetPrize() > oMoney)
                    {
                        return(false);
                    }
                    else
                    {
                        oMoney -= sds.GetPrize();
                    }
                }
            }
            else
            {
                return(false);
            }

            Dictionary <int, Dictionary <int, UnitCommandData> > unitCommandPool = command.isMine ? mUnitCommandPool : oUnitCommandPool;

            if (unitCommandPool.ContainsKey(_roundNum))
            {
                Dictionary <int, UnitCommandData> tmpDic = unitCommandPool[_roundNum];

                if (!tmpDic.ContainsKey(_commandID))
                {
                    tmpDic.Add(_commandID, command);
                }
            }
            else
            {
                Dictionary <int, UnitCommandData> tmpDic = new Dictionary <int, UnitCommandData>();

                unitCommandPool.Add(_roundNum, tmpDic);

                tmpDic.Add(_commandID, command);
            }
        }
        else if (_commandData is HeroCommandData)
        {
            HeroCommandData command = _commandData as HeroCommandData;

            IUnitSDS sds = getUnitCallBack(command.id);

            if (sds.GetIsHero())
            {
                if (command.isMine)
                {
                    if (mHeroCommandPool.ContainsKey(command.id) || mHeroPool.ContainsKey(command.id) || sds.GetPrize() > mMoney)
                    {
                        return(false);
                    }
                    else
                    {
                        mMoney -= sds.GetPrize();
                    }
                }
                else
                {
                    if (oHeroCommandPool.ContainsKey(command.id) || oHeroPool.ContainsKey(command.id) || sds.GetPrize() > oMoney)
                    {
                        return(false);
                    }
                    else
                    {
                        oMoney -= sds.GetPrize();
                    }
                }
            }
            else
            {
                return(false);
            }

            if (commandPool.ContainsKey(_roundNum))
            {
                Dictionary <int, CommandData> tmpDic = commandPool[_roundNum];

                if (!tmpDic.ContainsKey(_commandID))
                {
                    tmpDic.Add(_commandID, _commandData);
                }
            }
            else
            {
                Dictionary <int, CommandData> tmpDic = new Dictionary <int, CommandData>();

                commandPool.Add(_roundNum, tmpDic);

                tmpDic.Add(_commandID, _commandData);
            }

            Dictionary <int, HeroCommandData> tmpDic2 = _commandData.isMine ? mHeroCommandPool : oHeroCommandPool;

            tmpDic2.Add(command.id, command);
        }
        else if (_commandData is SkillCommandData)
        {
            SkillCommandData command = _commandData as SkillCommandData;

            Dictionary <int, SkillCommandData> skillDic = command.isMine ? mSkillCommandPool : oSkillCommandPool;

            Dictionary <int, Unit> heroDic = command.isMine ? mHeroPool : oHeroPool;

            if (heroDic.ContainsKey(command.id) && !skillDic.ContainsKey(command.id))
            {
                Unit hero = heroDic[command.id];

                if (hero.sds.GetSkill() == 0 || hero.skillCd > 0)
                {
                    return(false);
                }

                if (commandPool.ContainsKey(_roundNum))
                {
                    Dictionary <int, CommandData> tmpDic = commandPool[_roundNum];

                    if (!tmpDic.ContainsKey(_commandID))
                    {
                        tmpDic.Add(_commandID, _commandData);
                    }
                }
                else
                {
                    Dictionary <int, CommandData> tmpDic = new Dictionary <int, CommandData>();

                    commandPool.Add(_roundNum, tmpDic);

                    tmpDic.Add(_commandID, _commandData);
                }

                skillDic.Add(command.id, command);
            }
            else
            {
                return(false);
            }
        }

        return(true);
    }