using UnityEngine; using System.Collections; using System.Collections.Generic; using Sfs2X.Entities.Data; public class BattleStartHandler : BAHandler { public BattleStartHandler(BARoom room):base(room){} public override void HandleRequest (BAServer server, ISFSObject msg, int sender, int timeStamp) { room.isGameStart = true; if (!room.IsHost ()) return; int blueCount = 0; int redCount = 0; List list = room.GetUserList (); for(int i=0; i playerIdList = room.GetAvailabledPlayerIds (); int playerIdIndex = 0; int overflowIndex = 0; string[] nickArr = GetAINick (aiCount); ISFSArray arr = new SFSArray (); int halfMaxUsers = room.maxUsers / 2; for(int i=blueCount; i= playerIdList.Count) { playerId = room.maxUsers + overflowIndex; overflowIndex++; } else { playerId = playerIdList [playerIdIndex]; playerIdIndex++; } ISFSObject obj = new SFSObject (); obj.PutUtfString (UserSFSObjectLabel.ID, "-"+playerId.ToString()); obj.PutUtfString (UserSFSObjectLabel.NICK, nickArr[arr.Size()]); obj.PutInt (UserSFSObjectLabel.TEAM_ID, TeamUtil.Team.Blue.GetHashCode()); obj.PutInt (UserSFSObjectLabel.PLAYER_ID, playerId); arr.AddSFSObject (obj); } for(int i=redCount; i= playerIdList.Count) { playerId = room.maxUsers + overflowIndex; overflowIndex++; } else { playerId = playerIdList [playerIdIndex]; playerIdIndex++; } ISFSObject obj = new SFSObject (); obj.PutUtfString (UserSFSObjectLabel.ID, "-"+playerId.ToString()); obj.PutUtfString (UserSFSObjectLabel.NICK, nickArr[arr.Size()]); obj.PutInt (UserSFSObjectLabel.TEAM_ID, TeamUtil.Team.Red.GetHashCode()); obj.PutInt (UserSFSObjectLabel.PLAYER_ID, playerId); arr.AddSFSObject (obj); } ISFSObject data = new SFSObject (); data.PutSFSArray ("a", arr); Message pjMsg = new Message(Command.PlayerJoin, data); server.Send(pjMsg); } private string[] GetAINick(int count) { List list = new List{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 }; while(list.Count > count) { int index = Random.Range (0, list.Count); list.RemoveAt (index); } string[] arr = new string[count]; for(int i=0; i