Beispiel #1
0
        public void AddPlayer(ServerPlayer player)
        {
            if (player == null)
            return;

            foreach (ServerPlayer other in _players)
            if (other.accountID == player.accountID) {
                return;
            }

            foreach (ServerPlayer other in _players) {
            ServerMessage msg = new ServerMessage(Protocol.netPlayerAdd);
            msg.WriteInteger(this._ID);
            msg.WriteString(this._region.Name);
            msg.WriteInteger(other.TX);
            msg.WriteInteger(other.TY);
            msg.WriteByte(other.level);
            player.SendMessage(msg, other.accountID);
            msg = null;

            msg = other.GetKeysMessage();
            if (msg!=null) {
                player.SendMessage(msg, other.accountID);
                msg = null;
            }
            }

            _players.Add(player);
        }
Beispiel #2
0
        public bool AddPlayer(ServerPlayer player)
        {
            if (this.HasPlayer(player)) {
                return true;
            }

            if (this.IsFull()) {
                return false;
            }

            for (int i = 0; i < Settings.MaxPartySize; i++)
            if (_members[i] == null)
            {
                _members[i] = player;
                ServerMessage msg = new ServerMessage(Protocol.netSquadJoin);
                byte n = (byte)i;
                msg.WriteByte(n);
                this.Broadcast(msg, player.accountID);
                player.SendMessage(msg, player.accountID);
                msg = null;

                for (int j = 0; j < Settings.MaxPartySize; j++)
                if (_members[j]!= null && j!=i)
                {
                    msg = new ServerMessage(Protocol.netSquadJoin);
                    msg.WriteByte(n);

                    player.SendMessage(msg, _members[i].accountID);
                }

                break;
            }

            return true;
        }
Beispiel #3
0
 public virtual void Write(ServerMessage str)
 {
     str.WriteByte(opcode);
     str.WriteByte(index);
     str.WriteInteger(turn);
     str.WriteInteger(priority);
     str.WriteInteger(speed);
 }
Beispiel #4
0
        public void Update()
        {
            if (this.finished)
                return;

            if (this.loading)
            {
                if (Utils.GetTickCount() - loadTime > 1000 * 20)
                {
                    this.Cancel(null, ServerBattle.HashFailure);
                }

                return;
            }

            if (turnEnd)
            {
                foreach (ServerPlayer player in _players)
                {
                    if (player.turnState != BattleTurn.turnNext)
                        return;
                }

                turnEnd = false;

                byte state = BattleTurn.turnNext;

                foreach (ServerPlayer player in _players)
                {
                    ServerMessage msg = new ServerMessage(Protocol.netBattleTurn);
                    msg.WriteByte(state);
                    player.SendMessage(msg, 0);
                    player.turnState = BattleTurn.turnWaiting;
                }

                actionTime = Utils.GetTickCount();
                currentTurn = null;
                return;
            }

            if (currentTurn != null)
            {
                int result = currentTurn.Update();

                switch (result)
                {
                    case BattleTurn.turnTimeOut:
                        Utils.Log("Battle time out...", 0);
                        this.Cancel(null, winningSide);
                        return;

                    case BattleTurn.turnFinished:
                        _turns.Add(currentTurn);
                        actionTime = Utils.GetTickCount();

                        currentTurn.Finish();
                        turnEnd = true;
                        break;
                }

                if (Utils.GetTickCount() - actionTime > 1000 * 60 * 4)
                {
                    this.Cancel(null, ServerBattle.HashFailure);
                    return;
                }

            }
        }
Beispiel #5
0
        public void Start()
        {
            foreach (ServerPlayer p1 in _players)
            {
                p1.turnState = BattleTurn.turnLoading;

                foreach (ServerPlayer p2 in _players)
                {
                    if (p1 == p2)
                        continue;

                //Utils.Log("Sending opponent trainer info of " + p1.account.formattedPlayerName + " to " + p2.account.formattedPlayerName, 1);
                    ServerMessage msg = new ServerMessage(Protocol.netBattleTrainer);
                    msg.WriteByte(p1.battleTeam);
                    msg.WriteByte(p1.battleSide);
                    p2.SendMessage(msg, p1.accountID);
                }
            }

            // after sending info to everyone we let them start the battle
            foreach (ServerPlayer p1 in _players)
            {
                //Utils.Log("Sending battle start to " + p1.account.formattedPlayerName, 1);

                ServerMessage msg = new ServerMessage(Protocol.netBattleInit);
                p1.SendMessage(msg, p1.accountID);
            }
        }
Beispiel #6
0
        public void SetPlayerReady(ServerPlayer p)
        {
            if (!loading)
                return;

            p.turnState = BattleTurn.turnWaiting;

            byte count = 0;
            foreach (ServerPlayer player in _players)
            if (player.turnState != BattleTurn.turnLoading)
            {
                count++;
            }

            if (count< this._players.Count)
                return;

            this.loading = false;

            // after sending info to everyone we let them start the battle
            foreach (ServerPlayer player in _players)
            {
                ServerMessage msg = new ServerMessage(Protocol.netBattleStart);
                msg.WriteByte(count); // player count
                msg.WriteByte(this.secondsPerTurn); // player timer
                msg.WriteByte(this.battleMode); // team index
                msg.WriteInteger(this.seed);
                msg.WriteByte(player.battleTeam); // team index
                msg.WriteByte(player.battleSide); // local side
                msg.WriteByte(player.monstersPerBattle);
                player.rules.Write(msg);

                player.SendMessage(msg, player.accountID);
            }
        }
Beispiel #7
0
        public void Cancel(ServerPlayer ignore, byte cancelReason)
        {
            if (this.finished)
                return;

            foreach (ServerPlayer player in _players)
            {
                ServerMessage msg = new ServerMessage(Protocol.netBattleCancel);
                msg.WriteByte(cancelReason);

                player.SendMessage(msg, 0);
                player.ClearBattles();
            }

            this.finished = true;
        }
Beispiel #8
0
        public bool Finish()
        {
            UInt32 currentHash = 0;

            foreach (ServerPlayer player in battle.Players)
            if (currentHash  == 0 || player.battleHash != currentHash)
            {
                this.battle.Cancel(null, ServerBattle.HashFailure);
                return true;
            } else
            {
                player.turnState = turnFinished;
            }

            foreach (ServerBattleCommand cmd in commands)
            {
                foreach (ServerPlayer player in battle.Players)
                if (player != cmd.owner)
                {
                    //Log(logConsole, 'Battle', 'Sending command to ' + CardinalToString(Battle.Players[J].accountID) + ' -> ' + cmd.ToString());
                    cmd.SendTo(player);
                }
            }

            // now tell everyone that the turn can be executed
            foreach (ServerPlayer player in battle.Players)
            {
                ServerMessage msg = new ServerMessage(Protocol.netBattleTurn);
                msg.WriteByte(turnFinished);
                player.SendMessage(msg, 0);
            }

              return false;
        }
Beispiel #9
0
        public override void Write(ServerMessage str)
        {
            base.Write(str);

            str.WriteByte(targetTeam);
            str.WriteByte(targetMonster);
        }
Beispiel #10
0
 public override void Write(ServerMessage str)
 {
     base.Write(str);
     str.WriteByte(switchIndex);
     str.WriteByte(resetStats);
     str.WriteString(switchMsg);
 }
Beispiel #11
0
        public override void Write(ServerMessage str)
        {
            base.Write(str);

            str.WriteByte(sourceTeam);
            str.WriteByte(sourceMonster);
        }