12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661 |
- using UnityEngine;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using Sfs2X;
- using Sfs2X.Entities.Data;
- public class MessageManager
- {
- public BAServer server;
- public delegate void MessageCallBackDelegate(ISFSObject data);
- public delegate void MessageDealDelegate(string cmd, ISFSObject data);
- private Dictionary<string, MessageDealDelegate> messageDealDict;
- private List<ISFSObject> receiveQueue;
- private BattleSession battleSession;
- private float craftSyncDistance = 10f;
- public MessageManager()
- {
- server = new BAServer();
- server.SetMsgManCallBack(EnRecieveQueue);
- receiveQueue = new List<ISFSObject> ();
- //remove old message queue if exist
- MessageQueueUpdate mqu = GameObject.FindObjectOfType<MessageQueueUpdate>();
- if(mqu != null)
- GameObject.Destroy(mqu.gameObject);
- //create new message queue
- GameObject mquObj = new GameObject("MessageQueueUpdate");
- mqu = mquObj.AddComponent<MessageQueueUpdate>();
- mqu.messageManager = this;
- messageDealDict = new Dictionary<string, MessageDealDelegate>();
- messageDealDict.Add(Command.ConnectionError, OnConnectionError);
- messageDealDict.Add(Command.SearchRoom, OnSearchBattle);
- messageDealDict.Add(Command.BattleInfo, OnBattleInfo);
- messageDealDict.Add (Command.BattleExit, OnExitBattle);
- messageDealDict.Add (Command.AITaker, OnAITaker);
- messageDealDict.Add (Command.PlayerJoin, OnPlayerJoin);
- messageDealDict.Add(Command.PlayerLeft, OnPlayerLeft);
- messageDealDict.Add(Command.Ready, OnReady);
- messageDealDict.Add (Command.State, OnState);
- messageDealDict.Add(Command.CraftSelection, OnSelectCraft);
- messageDealDict.Add(Command.Move, OnMove);
- messageDealDict.Add(Command.Attack, OnPower);
- messageDealDict.Add(Command.Dead, OnDead);
- messageDealDict.Add (Command.PrepareSwap, OnPrepareSwap);
- messageDealDict.Add (Command.RequestSwap, OnRequestSwap);
- messageDealDict.Add(Command.Radio, OnRadio);
- messageDealDict.Add(Command.Station, OnOccupyStation);
- messageDealDict.Add(Command.AddMapItem, OnAddMapItem);
- messageDealDict.Add(Command.GetMapItem, OnGetItem);
- messageDealDict.Add(Command.AddFlag, OnAddFlag);
- messageDealDict.Add(Command.GetFlag, OnGetFlag);
- messageDealDict.Add(Command.PutFlag, OnPutFlag);
- messageDealDict.Add(Command.CaptureFlag, OnCaptureFlag);
- messageDealDict.Add(Command.SimpleSync, OnSimpleSync);
- //clan state
- messageDealDict.Add (Command.ClanInit, OnClanInit);
- messageDealDict.Add (Command.ClanOnline, OnClanOnline);
- messageDealDict.Add (Command.ClanOffline, OnClanOffline);
- messageDealDict.Add (Command.ClanBattle, OnClanBattle);
- messageDealDict.Add (Command.ClanMessage, OnClanMessage);
- messageDealDict.Add (Command.ClanJoin, OnClanJoin);
- messageDealDict.Add (Command.ClanLeft, OnClanLeft);
- //team
- messageDealDict.Add (Command.TeamInvite, OnTeamInvite);
- messageDealDict.Add (Command.TeamJoin, OnTeamJoin);
- messageDealDict.Add (Command.TeamLeft, OnTeamLeft);
- messageDealDict.Add (Command.TeamState, OnTeamState);
- messageDealDict.Add (Command.TeamKick, OnTeamKick);
- }
- public void SetBattleSession(BattleSession battleSession)
- {
- this.battleSession = battleSession;
- }
- public int myUserId
- {
- get{
- return Session.myUserId;
- }
- }
- private void EnSendQueue(Message msg)
- {
- server.Send(msg);
- }
- private void EnRecieveQueue(ISFSObject msg)
- {
- receiveQueue.Add (msg);
- }
- public void DeQueue()
- {
- if (BattleController.battleType == BattleController.BattleType.Edit)
- return;
-
- if (battleSession.IsReady ()) {
- for (int i = 0; i < receiveQueue.Count; i++) {
- ParseMessage (receiveQueue [i]);
- }
- receiveQueue.Clear ();
- }
- // else if(receiveQueue.Count > 0) {
- // ISFSObject msg = receiveQueue [0];
- // receiveQueue.RemoveAt (0);
- // ParseMessage (msg);
- // }
- server.Update();
- }
- private void ParseMessage(ISFSObject msg)
- {
- string cmd = msg.GetUtfString(Message.LABEL_COMMAND);
- ISFSObject data = msg.GetSFSObject(Message.LABEL_DATA);
- if(messageDealDict.ContainsKey(cmd))
- {
- messageDealDict[cmd](cmd, data);
- }
- else
- {
- Debuger.LogError("Can not parse command["+cmd+"]");
- }
- }
- private bool CheckError(string cmd, ISFSObject data)
- {
- if(data.ContainsKey("error"))
- {
- int error = data.GetInt ("error");
- Debuger.LogError (data.GetUtfString("errormsg"));
- return true;
- }
- return false;
- }
- public void Connect()
- {
- server.Connect ();
- }
- private void OnConnectionError(string cmd, ISFSObject data)
- {
- ProgressPanel.Hide();
- if(data.ContainsKey("success"))
- {
- if(!data.GetBool("success") && data.ContainsKey("error"))
- {
- int errorCode = data.GetInt("error");
- string errorInfo = Language.GetStr("Connection", "connectFail")+"["+errorCode+"]";
- // if(errorCode == SFSConnection.ERROR_CODE.LoginFailed.GetHashCode())
- // {
- // errorInfo = Language.GetStr("Connection", "loginFail");
- // }
- // else if(errorCode == SFSConnection.ERROR_CODE.ConnectLost.GetHashCode())
- // {
- // errorInfo = Language.GetStr("Connection", "connectLost");
- // }
- AlertPanel.Show(null, errorInfo, AlertPanel.OK, ConnectFail);
- }
- }
- }
- private void ConnectFail(AlertCloseEvent evt)
- {
- BattleController.battleType = BattleController.BattleType.Menu;
- Application.LoadLevel(Config.Scene.Battle.ToString());
- }
- public void Disconnect()
- {
- server.Disconnect();
- }
- public void EnterBase()
- {
- server.EnterBase ();
- }
- public void SearchBattle(MapData.Mode mode)
- {
- LocalToRemote ();
- battleSession.mode = mode;
- LoadingPanel panel = LoadingPanel.Show ();
- LoadingPanel.Increase (0.1f);
- panel.ReachTargetProgress.AddListener (()=>{
- server.SearchRoom ();
- });
- }
- private void OnSearchBattle(string cmd, ISFSObject data)
- {
- if(!CheckError(cmd, data))
- {
- string mapId = data.GetUtfString("m");
- battleSession.mapId = MapData.GetMapIdByName(mapId);
- if (battleSession.mapId != MapData.MapID.Base) {
- BattleController.battleType = BattleController.BattleType.Battle;
- battleSession.ResetBattle ();
- } else {
- BattleController.battleType = BattleController.BattleType.Menu;
- }
- int aiTakerUserId = StringUtil.ToInt(data.GetUtfString ("c"));
- battleSession.aiTakerUserId = aiTakerUserId;
- //init player
- ParsePlayer(data.GetSFSArray("a"));
- if (battleSession.mapId != MapData.MapID.Base)
- LoadingPanel.LoadScene (Config.Scene.Battle.ToString ());
- else {
- if (Session.GetInstance ().myUserData.isLogin) {
- CheckConnection ();
- } else {
- LoadingPanel.Increase (0.2f);
- Session.GetInstance ().GetNetworkManager ().Login (() => {
- battleSession.GetBattleController ().menuUI.clanChatBar.Refresh ();
- battleSession.SetMyPlayerId(Session.myUserId);
- CheckConnection ();
- if (LocalSaver.GetInstance ().noAutoBinding == 0)
- Session.GetInstance ().GetNetworkManager ().Binding ();
- });
- }
- }
- }
- }
- private void ParsePlayer(ISFSArray arr)
- {
- for(int i=0; i<arr.Count; i++)
- {
- ISFSObject obj = arr.GetSFSObject (i);
- int id = StringUtil.ToInt(obj.GetUtfString (UserSFSObjectLabel.ID));
- string nick = obj.GetUtfString (UserSFSObjectLabel.NICK);
- int team = obj.GetInt (UserSFSObjectLabel.TEAM_ID);
- int playerId = obj.GetInt (UserSFSObjectLabel.PLAYER_ID);
- Player player = battleSession.AddPlayer(id, nick, TeamUtil.GetTeam(team), playerId);
- }
- }
- private void OnPlayerJoin(string cmd, ISFSObject data)
- {
- ParsePlayer(data.GetSFSArray("a"));
- }
- private void ParseBuilding(ISFSArray arr)
- {
- Map map = battleSession.GetBattleController().GetMap();
- for(int i=0; i<arr.Count; i++)
- {
- ISFSObject obj = arr.GetSFSObject(i);
- MapObjectUtil.TypeId typeId = MapObjectUtil.GetTypeIdByCode(obj.GetInt("s"));
- if(typeId == MapObjectUtil.TypeId.Station)
- {
- StationData sd = new StationData();
- sd.team = TeamUtil.GetTeam(obj.GetInt("t"));
- sd.userId = obj.GetInt ("u");
- sd.id = obj.GetInt("i");
- sd.crystalId = obj.GetInt("c");
- Station station = map.CreateStation(sd, battleSession.GetBattleController());
- station.hp = station.maxHp;
- }
- else if(typeId == MapObjectUtil.TypeId.Door)
- {
- Door door = map.GetDoorByIndex(obj.GetInt("c"));
- CraftData craftData = new CraftData(1002);
- craftData.userId = obj.GetInt("u");
- craftData.id = obj.GetInt("i");
- craftData.team = TeamUtil.GetTeam(obj.GetInt("t"));
- craftData.position = door.transform.position;
- craftData.isHero = true;
- craftData.aiType = AI.AIType.Door;
- door.Init(map, craftData);
- DoorAI ai = door.gameObject.AddComponent<DoorAI>();
- ai.init(battleSession.GetBattleController());
- Player player = battleSession.GetPlayer(craftData.userId);
- ai.SetPlayer(player);
- battleSession.GetBattleController().battleUI.miniMap.CreateCraft(door);
- map.AddBattleObject(door);
- }
- else if(typeId == MapObjectUtil.TypeId.MapItemPos)
- {
- int id = obj.GetInt("i");
- int itemId = obj.GetInt("t");
- if(itemId != -1)
- {
- MapItemData itemData = new MapItemData();
- itemData.id = id;
- itemData.typeId = itemId;
- MapItemPos mapItemPos = battleSession.GetBattleController().GetMap().GetMapItemPos(id);
- itemData.postion = mapItemPos.position;
- MapItem mapItem = battleSession.GetBattleController().GetMap().CreateMapItem(itemData);
- mapItemPos.item = mapItem;
- }
- }
- else if(typeId == MapObjectUtil.TypeId.Flag)
- {
- int id = obj.GetInt("i");
- int itemId = obj.GetInt("t");
- if(itemId != -1)
- {
- MapItemData itemData = new MapItemData();
- itemData.id = id;
- itemData.typeId = itemId;
- MapItemPos mapItemPos = battleSession.GetBattleController().GetMap().GetMapItemPos(id);
- itemData.postion = mapItemPos.position;
- MapItem mapItem = battleSession.GetBattleController().GetMap().CreateMapItem(itemData);
- mapItemPos.item = mapItem;
- }
- }
- }
- map.RemoveNoIdDoor();
- }
- private void OnPlayerLeft(string cmd, ISFSObject data)
- {
- if(!battleSession.IsReady() || battleSession.IsOver())
- return;
-
- int userId = StringUtil.ToInt(data.GetUtfString("u"));
- battleSession.PlayerLeft (userId);
- }
- private void RemoteToLocal()
- {
- server.SetConnection (BAServer.ConnectionType.Local);
- }
- private void LocalToRemote()
- {
- server.SetConnection (BAServer.ConnectionType.Remote);
- }
- public void Ready()
- {
- ISFSObject data = new SFSObject();
- Message msg = new Message(Command.Ready, data);
- EnSendQueue(msg);
- }
- private void OnReady(string cmd, ISFSObject data)
- {
- if (data != null) {
- int receiver = data.GetInt ("r");
- if(receiver != myUserId)
- {
- SendState (receiver);
- return;
- }
- int freeTime = data.GetInt ("f");
- int time = data.GetInt ("t");
- battleSession.GetBattleController ().clock.freeTimeLeft = (float)freeTime / 1000f;
- battleSession.GetBattleController ().clock.timeLeft = (float)time / 1000f;
- ParseBuilding (data.GetSFSArray ("l"));
- if (data.ContainsKey ("a"))
- ParsePlayer (data.GetSFSArray ("a"));
- }
- WaitLoadComplete ();
- }
- private void CheckConnection()
- {
- if (Session.GetInstance ().myUserData.clanId > 0) {
- LocalToRemote ();
- battleSession.GetMessageManager ().Ready ();
- } else {
- // battleSession.GetMessageManager ().Connect ();
- RemoteToLocal ();
- OnReady (Command.Ready.ToString(), null);
- }
- }
- private void WaitLoadComplete()
- {
- if(LoadingPanel.GetCurrentPanel() != null)
- LoadingPanel.Complete (OnLoadBattleComplete);
- }
- private void OnLoadBattleComplete()
- {
- battleSession.GetBattleController().ReadyToFight();
- }
- private void SendState(int target)
- {
- ISFSArray arr = new SFSArray ();
- PlayerCraftObjToArr (battleSession.myPlayer, arr);
- if (battleSession.aiTakerUserId == myUserId) {
- List<Player> list = battleSession.GetPlayerList ();
- for(int i=0; i<list.Count; i++)
- {
- Player player = list [i];
- if(player.IsAI())
- {
- PlayerCraftObjToArr (player, arr);
- }
- }
- }
- if (arr.Size () == 0)
- return;
- ISFSObject data = new SFSObject ();
- data.PutInt ("t", target);
- data.PutSFSArray ("a", arr);
- Message msg = new Message (Command.State, data);
- EnSendQueue (msg);
- }
- private void OnState(string cmd, ISFSObject data)
- {
- int target = data.GetInt ("t");
- ISFSArray arr = data.GetSFSArray ("a");
- if (target != myUserId)
- return;
-
- for(int i=0; i<arr.Size(); i++)
- {
- ParseStateObject (arr.GetSFSObject (i));
- }
- }
- private void PlayerCraftObjToArr(Player player, ISFSArray arr)
- {
- Player.Hero hero = player.GetHero ();
- if(hero.GetCraft() != null)
- {
- arr.AddSFSObject(GetStateCraftObj(hero.GetCraft()));
- }
- else if(hero.craftLandingData != null)
- {
- arr.AddSFSObject (GetStateCraftObj (hero.craftLandingData));
- }
- Craft[] soldierArr = hero.soldierArr;
- for(int i=0; i<soldierArr.Length; i++)
- {
- Craft craft = soldierArr [i];
- if(craft != null)
- {
- arr.AddSFSObject (GetStateCraftObj(craft));
- }
- }
- }
- private ISFSObject GetStateCraftObj(Craft craft)
- {
- ISFSObject obj = new SFSObject();
- obj.PutInt("u", craft.userId);
- obj.PutInt("i", craft.id);
- obj.PutInt("c", craft.GetCraftId());
- obj.PutInt("t", craft.team.GetHashCode());
- obj.PutFloat("sx", craft.position.x);
- obj.PutFloat("sy", craft.position.z);
- obj.PutBool("h", craft.IsHero());
- if(craft.isMoving)
- {
- obj.PutInt("ex", craft.targetMovePosition.x);
- obj.PutInt("ey", craft.targetMovePosition.y);
- }
- obj.PutFloat("hp", craft.hp);
- return obj;
- }
- private ISFSObject GetStateCraftObj(CraftData craft)
- {
- ISFSObject obj = new SFSObject();
- obj.PutInt("u", craft.userId);
- obj.PutInt("i", craft.id);
- obj.PutInt("c", craft.GetCraftId());
- obj.PutInt("t", craft.team.GetHashCode());
- obj.PutFloat("sx", craft.position.x);
- obj.PutFloat("sy", craft.position.z);
- obj.PutBool("h", craft.isHero);
-
- obj.PutFloat("hp", craft.GetMaxHp());
- return obj;
- }
- private void ParseStateObject(ISFSObject obj)
- {
- int userId = obj.GetInt ("u");
- Player player = battleSession.GetPlayer (userId);
- if (player == null)
- return;
- CraftData craftData = new CraftData(obj.GetInt("c"));
- craftData.id = obj.GetInt("i");
- craftData.userId = player.userId;
- craftData.nick = player.nick;
- craftData.team = TeamUtil.GetTeam(obj.GetInt("t"));
- craftData.position = new Vector3(obj.GetFloat("sx"), 0, obj.GetFloat("sy"));
- craftData.isHero = obj.GetBool("h");
- if(craftData.isHero)
- craftData.aiType = AI.AIType.Hero;
- else
- craftData.aiType = AI.AIType.Soldier;
- Craft craft = battleSession.GetBattleController().CreateCraft(craftData);
- if(obj.ContainsKey("p"))
- {
- // TODO craft power
- }
- if(craft.IsHero())
- player.GetHero().SetCraft(craft);
- else
- player.GetHero().SetSoldier(craft);
- craft.PositionTo(new Vector3(obj.GetFloat("sx"), 0, obj.GetFloat("sy")));
- craft.hp = obj.GetFloat("hp");
- if(obj.ContainsKey("ex"))
- {
- craft.MoveTo(obj.GetInt("ex"), obj.GetInt("ey"));
- }
- // TODO buff
- // TODO target
- }
- public void SelectCraft(Player player, int craftId, int col, int row)
- {
- Player.Hero hero = player.GetHero();
- hero.lastSelectTime = GameTime.time;
- ISFSObject data = new SFSObject();
- data.PutInt("u", player.userId);
- data.PutInt("c", craftId);
- data.PutInt("x", col);
- data.PutInt("y", row);
- if (player.isMe) {
- data.PutInt ("h", HaloManager.GetInstance ().GetCurrentEquipedId ());
- data.PutInt ("s", SkinManager.GetInstance().GetSkinId(craftId));
- }
- Message msg = new Message(Command.CraftSelection, data);
- EnSendQueue(msg);
- }
- private void OnSelectCraft(string cmd, ISFSObject data)
- {
- int userId = data.GetInt("u");
- float x = Map.GetCenterX(data.GetInt("x"));
- float y = Map.GetCenterZ(data.GetInt("y"));
- Player player = battleSession.GetPlayer(data.GetInt("u"));
- int haloId = 0;
- if(data.ContainsKey("h"))
- haloId = data.GetInt("h");
- int skinId = 0;
- if (data.ContainsKey ("s"))
- skinId = data.GetInt ("s");
- if(player != null)
- {
- Player.Hero hero = player.GetHero();
- hero.lastSelectTime = float.MinValue;
- if (hero.GetCraft() != null) {
- return;
- }
- CraftData craftData = new CraftData(data.GetInt("c"));
- craftData.id = player.GetHeroUid();
- craftData.userId = player.userId;
- craftData.position = new Vector3(x, 0, y);
- craftData.team = player.team;
- if(userId == myUserId)
- {
- craftData.aiType = AI.AIType.Manual;
- }
- else if(userId < 0)
- {
- craftData.aiType = AI.AIType.Hero;
- }
- else
- {
- craftData.aiType = AI.AIType.Remote;
- }
- craftData.nick = player.nick;
- craftData.isHero = true;
- craftData.haloId = haloId;
- craftData.skinId = skinId;
- hero.craftLandingData = craftData;
- // Craft craft = battleSession.GetBattleController().CreateCraft(craftData);
- battleSession.GetBattleController().CreateCapsule(craftData);
- }
- else
- {
- Debuger.LogError("OnSelectCraft Can not find Player "+userId.ToString());
- }
- }
- public void Move(Craft craft, int col, int row)
- {
- Message msg = new MoveMessage(craft.id, col, row);
- EnSendQueue(msg);
- // if(craft.aiType == AI.AIType.Manual)
- // {
- // craft.MoveTo(col, row);
- // }
- }
- private void OnMove(string cmd, ISFSObject data)
- {
- int craftId = data.GetInt("i");
- int x = data.GetInt("x");
- int y = data.GetInt("y");
- // float sx = data.GetFloat ("sx");
- // float sy = data.GetFloat ("sy");
- // Vector3 startPos = new Vector3 (sx, 0, sy);
- Craft craft = battleSession.GetBattleController().GetMap().GetBattleObject(craftId) as Craft;
- if(craft != null)
- {
- // if(NumberUtil.distanceVector3(craft.position, startPos, true) > craftSyncDistance)
- // craft.position = startPos;
- craft.MoveTo(x, y);
- }
- else
- {
- Debuger.LogError("onReceiveMove::can not find craft with id("+craftId+")");
- }
- }
- public void Target(Craft craft)
- {
- ISFSObject data = new SFSObject();
- data.PutInt("i", craft.id);
- PackTarget(craft.target, data);
- Message msg = new Message(Command.Target, data);
- EnSendQueue(msg);
- }
- private void PackTarget(ITarget target, ISFSObject data)
- {
- if(target is BattleObject)
- {
- BattleObject battleObj = target as BattleObject;
- data.PutInt("ti", battleObj.id);
- data.PutInt("tt", TargetUtil.GetTargetType(battleObj).GetHashCode());
- }
- }
- private void OnTarget(string cmd, ISFSObject data)
- {
- Craft craft = battleSession.GetBattleController().GetMap().GetBattleObject(data.GetInt("i")) as Craft;
- if(craft != null && craft.userId != myUserId)
- {
- craft.target = ParseTarget(data);
- if(craft.target == null)
- {
- craft.StopMove();
- }
- }
- }
- private ITarget ParseTarget(ISFSObject data)
- {
- if(data.ContainsKey("ti"))
- {
- int targetId = data.GetInt("ti");
- TargetUtil.TargetType targetType = TargetUtil.GetTargetTypeByCode(data.GetInt("tt"));
- if(targetType == TargetUtil.TargetType.CrystalBase)
- {
- return battleSession.GetBattleController().GetMap().GetCrystalBase(targetId).GetStation();
- }
- else if(targetType == TargetUtil.TargetType.Craft)
- {
- return battleSession.GetBattleController().GetMap().GetBattleObject(targetId);
- }
- }
- return null;
- }
- public void Power(Power power, ITarget target)
- {
- int powerId = power.GetId ();
- IPowerOwner owner = power.GetOwner ();
- ISFSObject powerData = power.PackMessage(target, battleSession.GetBattleController());
- Message msg = new PowerMessage(power, powerData);
- EnSendQueue(msg);
- }
- private void OnPower(string cmd, ISFSObject data)
- {
- int userId = data.GetInt ("u");
- int craftId = data.GetInt("i");
- int powerId = data.GetInt("p");
- int crystalNeed = data.GetInt ("c");
- ISFSObject powerData = data.GetSFSObject("d");
- IPowerOwner owner = battleSession.GetBattleController().GetMap().GetBattleObject(craftId) as IPowerOwner;
- if(owner != null)
- {
- Vector3 pos = new Vector3(data.GetFloat("x"), 0, data.GetFloat("y"));
- if(NumberUtil.distanceVector3(owner.position, pos, true) > craftSyncDistance)
- owner.position = pos;
- if (crystalNeed > 0)
- {
- Player player = battleSession.GetPlayer (userId);
- if(userId == myUserId)
- {
- Session.GetInstance ().myUserData.coin -= crystalNeed;
- player.coinSpend += crystalNeed;
- }
- }
- owner.GetPowerManager ().ParsePower (powerId, powerData, battleSession.GetBattleController ());
- }
- else
- {
- Debuger.LogError("onReceivePower::can not find craft with id("+craftId+")");
- }
- }
- public void Dead(BattleObject battleObj, int killerUserId, int killerCraftId)
- {
- ISFSObject data = new SFSObject();
- data.PutInt("i", battleObj.id);
- data.PutInt("m", battleObj.team.GetHashCode());
- data.PutInt("c", battleObj is Craft ? (battleObj as Craft).GetCraftId() : 0);
- data.PutInt("t", battleObj.typeId);
- data.PutInt("u", battleObj.userId);
- data.PutInt("ku", killerUserId);
- data.PutInt("kc", killerCraftId);
- data.PutInt("x", battleObj.col);
- data.PutInt("y", battleObj.row);
-
- Message msg = new Message(Command.Dead, data);
- EnSendQueue(msg);
-
- if(battleObj.userId == myUserId)
- {
- battleSession.GetBattleController().DealDeath(battleObj.userId, battleObj.id, killerUserId);
- }
- }
- private void OnDead(string cmd, ISFSObject data)
- {
- int objid = data.GetInt("i");
- TeamUtil.Team team = TeamUtil.GetTeam (data.GetInt("m"));
- int killerUserId = data.GetInt("ku");
- Map map = battleSession.GetBattleController ().GetMap ();
- IBattleObject battleObj = map.GetBattleObject(objid);
- if (battleObj != null) {
- battleSession.GetBattleController().DealDeath(battleObj.userId, battleObj.id, killerUserId);
- }
- team = TeamUtil.GetOpponentTeam (team);
- FlagItem flag = map.GetFlag(team);
- if(flag != null && flag.linkedCraftId == objid)
- {
- int x = data.GetInt("x");
- int y = data.GetInt("y");
- AStarNode node = map.GetAStarNode(x, y);
- if(node == null)
- {
- node = map.FindNearestEmptyAstarNode(x, y);
- }
-
- if(node == null)
- {
- FlagBase flagBase = map.GetFlagBase(team);
- flag.PutToBase(flagBase.position);
- }
- else
- {
- flag.PutGround(map.GetAstarNodePosition(node.X, node.Y));
- }
-
- Player player = battleSession.GetPlayer(data.GetInt("u"));
- if(player != null)
- {
- string info = Language.GetStr("Flag", "flagLose");
- info = info.Replace("%COLOR%", TeamUtil.GetTeamColorString(player.team));
- info = info.Replace("%NICK%", player.nick);
- info = info.Replace("%TEAM%", TeamUtil.GetTeamName(team));
- battleSession.GetBattleController().battleUI.ShowBottomTip(info);
- }
- }
- }
- public void OccupyStation(Craft craft, CrystalBase crystalBase)
- {
- ISFSObject data = new SFSObject();
- data.PutInt("c", crystalBase.id);
- data.PutInt("t", craft.team.GetHashCode());
- data.PutInt("u", craft.userId);
- Message msg = new Message(Command.Station, data);
- EnSendQueue(msg);
- }
- private void OnOccupyStation(string cmd, ISFSObject data)
- {
- if(data.ContainsKey("i"))
- {
- Map map = battleSession.GetBattleController().GetMap();
- int userId = data.GetInt ("u");
- StationData stationData = new StationData();
- stationData.team = TeamUtil.GetTeam(data.GetInt("t"));
- stationData.userId = userId;
- stationData.id = data.GetInt("i");
- stationData.crystalId = data.GetInt("c");
- Station station = map.CreateStation(stationData, battleSession.GetBattleController());
- Player player = battleSession.GetPlayer(userId);
- if(player != null)
- {
- player.station++;
- string colorStr = TeamUtil.GetTeamColorString(player.team);
- string info = Language.GetStr("GameInfo", "occupy");
- info = info.Replace("%DIRECTION%", Language.GetStr(map.id.ToString(), "station"+station.crystalBase.id));
- if(player.userId == myUserId)
- {
- info = info.Replace("%NAME%", Language.GetStr("GameInfo", "you"));
- }
- else
- {
- info = info.Replace("%NAME%", player.nick);
- }
- info = info.Replace("%COLOR%", colorStr);
- battleSession.GetBattleController().battleUI.ShowBottomTip(info);
- }
- }
- }
- private bool radioHold = false;
- public void Radio(int index)
- {
- if(!radioHold)
- {
- ISFSObject data = new SFSObject();
- data.PutInt("i", index);
- data.PutInt("u", myUserId);
- int craftId = battleSession.GetBattleController ().GetCtrlCraft() != null ? battleSession.GetBattleController ().GetCtrlCraft().id : 0;
- data.PutInt ("c", craftId);
- radioHold = true;
- Message msg = new Message(Command.Radio, data);
- EnSendQueue(msg);
- }
- battleSession.GetBattleController().battleUI.HideRadioPanel();
- }
- private void OnRadio(string cmd, ISFSObject data)
- {
- int userId = data.GetInt("u");
- int index = data.GetInt("i");
- int craftId = data.GetInt ("c");
- if(userId == myUserId)
- {
- radioHold = false;
- }
- battleSession.GetBattleController().battleUI.DealRadio(userId, craftId, index);
- }
- // private void ResetPlayer(Player player)
- // {
- // player.heroDeadTime = 0;
- // if(player.heroCraft != null)
- // {
- // battleSession.GetBattleController().DoDeath(player.heroCraft);
- // }
- // player.ClearHero();
- // }
- // public static void ParseStaticMapObject(ISFSArray arr, BattleSession battleSession)
- // {
- // ParseBuilding(arr);
- // for(int i=0; i<arr.Count; i++)
- // {
- // ISFSObject obj = arr.GetSFSObject(i);
- // MapObjectUtil.TypeId typeId = MapObjectUtil.GetTypeIdByCode(obj.GetInt("s"));
- // if(typeId == MapObjectUtil.TypeId.Station)
- // {
- // StationData stationData = new StationData();
- // stationData.id = obj.GetInt("i");
- // stationData.team = TeamUtil.GetTeam(obj.GetInt("t"));
- // stationData.crystalId = obj.GetInt("c");
- // Station station = battleSession.GetBattleController().GetMap().CreateStation(stationData, battleSession.GetBattleController());
- //
- // if(obj.ContainsKey("ti"))
- // {
- // int itemId = obj.GetInt("ti");
- // int itemTypeId = obj.GetInt("tt");
- // MapItemData itemData = new MapItemData();
- // itemData.id = itemId;
- // itemData.typeId = itemTypeId;
- // itemData.postion = station.itemPosition;
- // itemData.team = station.team;
- // battleSession.GetBattleController().GetMap().CreateMapItem(itemData);
- // }
- // }
- // else if(typeId == MapObjectUtil.TypeId.Door)
- // {
- //
- // }
- // }
- // }
- private void OnAddMapItem(string cmd, ISFSObject data)
- {
- Map map = battleSession.GetBattleController().GetMap();
- ISFSArray arr = data.GetSFSArray("l");
- for(int i=0; i<arr.Count; i++)
- {
- ISFSObject obj = arr.GetSFSObject(i);
- int id = obj.GetInt("i");
- int itemId = obj.GetInt("t");
- MapItemPos mapItemPos = map.GetMapItemPos(id);
- if(mapItemPos != null)
- {
- MapItemData itemData = new MapItemData();
- itemData.id = id;
- itemData.typeId = itemId;
- itemData.postion = mapItemPos.position;
- map.CreateMapItem(itemData);
- }
- }
- }
- public void GetItem(Player player, int craftId, int itemId)
- {
- ISFSObject data = new SFSObject();
- data.PutInt("u", player.userId);
- data.PutInt("c", craftId);
- data.PutInt("i", itemId);
- Message msg = new Message(Command.GetMapItem, data);
- EnSendQueue(msg);
- }
-
- private void OnGetItem(string cmd, ISFSObject data)
- {
- int itemId = data.GetInt("i");
- int craftId = data.GetInt ("c");
- int userId = data.GetInt("u");
- MapItem mapItem = battleSession.GetBattleController().GetMap().GetMapItem(itemId);
- if(mapItem != null)
- {
- BattleObject battleObj = battleSession.GetBattleController ().GetMap ().GetBattleObject (craftId);
- if(battleObj != null)
- {
- Buff buff = BuffManager.GetInstance().AddBuff(8, battleObj, battleObj);
- }
- mapItem.Remove();
- }
- }
- public static void ParseFlag(ISFSArray arr, BattleSession battleSession)
- {
- Map map = battleSession.GetBattleController().GetMap();
- for(int i=0; i<arr.Count; i++)
- {
- ISFSObject obj = arr.GetSFSObject(i);
- TeamUtil.Team team = TeamUtil.GetTeam(obj.GetInt("t"));
- int x = obj.GetInt("x");
- int y = obj.GetInt("y");
- int craftId = obj.GetInt("c");
- FlagItem flag = map.GetFlag(team);
- bool isNew = false;
- if(flag == null)
- {
- isNew = true;
- flag = map.CreateFlag(team);
- }
- if(craftId != -1)
- {
- PutFlagToCraft(craftId, flag, map);
- }
- else if(isNew)
- {
- flag.PutToBase(map.GetFlagBase(flag.team).position);
- string info = Language.GetStr("Flag", "flagPlace");
- info = info.Replace("%COLOR%", TeamUtil.GetTeamColorString(flag.team));
- info = info.Replace("%TEAM%", TeamUtil.GetTeamName(flag.team));
- }
- else if(x == 0 && y == 0)
- {
- flag.PutToBase(map.GetFlagBase(flag.team).position);
- }
- else if(flag.IsOnGround())
- {
- flag.position = new Vector3(x, 0, y);
- AStarNode astarNode = map.GetAStarNodeByPosition(flag.position);
- if(!astarNode.IsWalkable(null))
- {
- astarNode = map.FindNearestEmptyAstarNode(astarNode.X, astarNode.Y);
- if(astarNode != null)
- {
- flag.position = new Vector3(Map.GetCenterX(astarNode.X), 0, Map.GetCenterZ(astarNode.Y));
- }
- }
- flag.PutGround(flag.position);
- }
- }
- }
- public static void PutFlagToCraft(int id, FlagItem flag, Map map)
- {
- Craft craft = map.GetBattleObject(id) as Craft;
- if(craft != null)
- {
- flag.LinkToCraft(craft);
- }
- else
- {
- flag.WaitToLinkId(id);
- }
- }
- private void OnFlagSync(string cmd, ISFSObject data)
- {
- ParseFlag(data.GetSFSArray("l"), battleSession);
- }
- private void OnAddFlag(string cmd, ISFSObject data)
- {
- ParseFlag(data.GetSFSArray("l"), battleSession);
- }
- public void GetFlag(Player player, Craft hero, FlagItem flag)
- {
- if(hero != null)
- {
- ISFSObject data = new SFSObject();
- data.PutInt("i", hero.id);
- data.PutInt("t", flag.team.GetHashCode());
- data.PutInt("u", player.userId);
- Message msg = new Message(Command.GetFlag, data);
- EnSendQueue(msg);
- }
- }
- private void OnGetFlag(string cmd, ISFSObject data)
- {
- Map map = battleSession.GetBattleController().GetMap();
- int craftId = data.GetInt("i");
- TeamUtil.Team team = TeamUtil.GetTeam(data.GetInt("t"));
- Craft craft = map.GetBattleObject(craftId) as Craft;
- if(craft != null)
- {
- FlagItem flag = map.GetFlag(team);
- if(flag != null)
- flag.LinkToCraft(craft);
- string info = Language.GetStr("Flag", "flagGet");
- info = info.Replace("%COLOR%", TeamUtil.GetTeamColorString(craft.team));
- info = info.Replace("%NICK%", craft.nick);
- info = info.Replace("%TEAM%", TeamUtil.GetTeamName(team));
- battleSession.GetBattleController().battleUI.ShowBottomTip(info);
- }
- }
- public void ReturnFlag(Player player, Craft craft, FlagItem flag)
- {
- PutFlag(player, craft, flag);
- }
- public void PutFlag(Player player, Craft craft, FlagItem flag)
- {
- ISFSObject data = new SFSObject();
- data.PutInt("t", flag.team.GetHashCode());
- data.PutInt("u", player.userId);
- data.PutInt ("i", craft.id);
- data.PutInt("x", 0);
- data.PutInt("y", 0);
- Message msg = new Message(Command.PutFlag, data);
- EnSendQueue(msg);
- }
- private void OnPutFlag(string cmd, ISFSObject data)
- {
- TeamUtil.Team team = TeamUtil.GetTeam(data.GetInt("t"));
- int x = data.GetInt("x");
- int y = data.GetInt("y");
- Map map = battleSession.GetBattleController().GetMap();
- FlagItem flag = map.GetFlag(team);
- if(flag == null)
- return;
- FlagBase flagBase = map.GetFlagBase(team);
- flag.PutToBase(flagBase.position);
- Player player = battleSession.GetPlayer(data.GetInt("u"));
- if(player != null)
- {
- string info = Language.GetStr("Flag", "flagReturn");
- info = info.Replace("%COLOR%", TeamUtil.GetTeamColorString(player.team));
- info = info.Replace("%NICK%", player.nick);
- info = info.Replace("%TEAM%", TeamUtil.GetTeamName(team));
- battleSession.GetBattleController().battleUI.ShowBottomTip(info);
- }
- }
- public void CaptureFlag(Player player, Craft hero)
- {
- Map map = battleSession.GetBattleController().GetMap();
- if(hero != null)
- {
- FlagItem myFlag = map.GetFlag(player.team);
- FlagItem oppFlag = map.GetFlag(TeamUtil.GetOpponentTeam(player.team));
- if(myFlag != null && oppFlag != null && oppFlag.linkedCraftId == hero.id && myFlag.IsInBase())
- {
- ISFSObject data = new SFSObject();
- data.PutInt("i", hero.id);
- data.PutInt("t", player.team.GetHashCode());
- data.PutInt("u", player.userId);
- Message msg = new Message(Command.CaptureFlag, data);
- EnSendQueue(msg);
- }
- }
- }
- private void OnCaptureFlag(string cmd, ISFSObject data)
- {
- Player player = battleSession.GetPlayer(data.GetInt("u"));
- if(player != null)
- {
- string info = Language.GetStr("Flag", "flagCapture");
- info = info.Replace("%COLOR%", TeamUtil.GetTeamColorString(player.team));
- info = info.Replace("%NICK%", player.nick);
- info = info.Replace("%TEAM%", TeamUtil.GetTeamName(player.team));
- battleSession.GetBattleController().battleUI.ShowBottomTip(info);
- }
- battleSession.GetBattleController().GetMap().CleanFlag();
- }
- private void OnBattleInfo(string cmd, ISFSObject data)
- {
- if(data.ContainsKey("s"))
- DealScore(data.GetSFSObject("s"));
- // if(data.ContainsKey("p"))
- // DealAiPlayerChange(data.GetSFSObject("p"));
- // if(data.ContainsKey("a"))
- // DealAiTaker(data.GetSFSObject("a"));
- }
- private void DealScore(ISFSObject data)
- {
- BattleController battleController = battleSession.GetBattleController();
- if(battleController == null)
- return;
-
- if(data.ContainsKey("w"))
- {
- battleController.GameOver(TeamUtil.GetTeam(data.GetInt("w")));
- }
-
- battleController.blueScore = data.GetInt("b");
- battleController.redScore = data.GetInt("r");
- battleController.battleUI.scoreBar.updateScore(battleController.blueScore, battleController.redScore);
-
- battleController.clock.freeTimeLeft = (float)data.GetInt("f")/1000f;
- battleController.clock.timeLeft = (float)data.GetInt("t")/1000f;
- if(!battleController.isBattleStart && battleController.clock.freeTimeLeft == 0)
- {
- battleController.isBattleStart = true;
- battleController.GetMap().ClearBlocks(TeamUtil.Team.Yellow);
- }
- if(data.ContainsKey("fl"))
- {
- ParseFlag(data.GetSFSArray("fl"), battleSession);
- }
- }
- // private void DealAiTaker(ISFSObject data)
- // {
- // if(!data.ContainsKey("a"))
- // return;
- //
- // ISFSArray arr = data.GetSFSArray("a");
- // for(int i=0; i<arr.Count; i++)
- // {
- // ISFSObject obj = arr.GetSFSObject(i);
- // int userId = obj.GetInt("u");
- // int aiTaker = obj.GetInt("t");
- // Player player = battleSession.GetPlayer(userId);
- // if(player != null && player.IsAI())
- // {
- // player.aiTakerId = aiTaker;
- // }
- // }
- // }
- //
- // private void DealAiPlayerChange(ISFSObject data)
- // {
- // if(data.ContainsKey("a"))
- // {
- // ISFSArray arr = data.GetSFSArray("a");
- // for(int i=0; i<arr.Count; i++)
- // {
- // ISFSObject obj = arr.GetSFSObject(i);
- // battleSession.AddPlayer(obj.GetInt("u"), obj.GetUtfString("n"), TeamUtil.GetTeam(obj.GetInt("t")), -1);
- // }
- // }
- // }
- public void SimpleSync()
- {
- ISFSObject data = new SFSObject ();
- Message msg = new SyncMessage ();
- EnSendQueue (msg);
- }
- private void OnSimpleSync(string cmd, ISFSObject data)
- {
- }
- private void OnAITaker(string cmd, ISFSObject data)
- {
- Debuger.Log ("OnAITaker "+data.GetDump());
- int aiTaker = data.GetInt ("a");
- battleSession.aiTakerUserId = aiTaker;
- }
- public void PrepareSwap(int id, int craftId)
- {
- ISFSObject data = new SFSObject();
- data.PutInt("i", id);
- data.PutInt("s", craftId);
- Message msg = new Message(Command.PrepareSwap, data);
- EnSendQueue(msg);
- }
- private void OnPrepareSwap(string cmd, ISFSObject data)
- {
- int id = data.GetInt ("i");
- int craftId = data.GetInt ("s");
- Craft craft = battleSession.GetBattleController().GetMap().GetBattleObject(id) as Craft;
- if(craft != null)
- craft.GetSwapManager().PrepareSwap(craftId);
- }
- public void RequestSwap(int id, int craftId)
- {
- ISFSObject data = new SFSObject();
- data.PutInt("i", id);
- data.PutInt("s", craftId);
- Message msg = new Message(Command.RequestSwap, data);
- EnSendQueue(msg);
- }
- private void OnRequestSwap(string cmd, ISFSObject data)
- {
- int id = data.GetInt ("i");
- int craftId = data.GetInt ("s");
- Craft craft = battleSession.GetBattleController().GetMap().GetBattleObject(id) as Craft;
- if(craft != null)
- {
- craft.GetSwapManager().RequestedSwap();
- battleSession.GetBattleController().CreateCapsule(id, craftId);
- }
- }
- public void ExitBattle()
- {
- Session.GetInstance().myUserData.vipNextRound = false;
- LoadingPanel loadingPanel = LoadingPanel.Show(false);
- loadingPanel.ReachTargetProgress.AddListener (CheckSaveReplay);
- LoadingPanel.Increase(0.2f);
- battleSession.GetBattleController().isExit = true;
- // BattleController.battleType = BattleController.BattleType.Menu;
- // LoadingPanel.LoadScene(Config.Scene.Battle.ToString());
- }
- private void CheckSaveReplay()
- {
- ReplayManager.GetInstance ().Save (battleSession);
- LoadingPanel loadingPanel = LoadingPanel.Show();
- loadingPanel.ReachTargetProgress.RemoveListener (CheckSaveReplay);
- LoadingPanel.Increase(0.3f);
- ISFSObject data = new SFSObject();
- data.PutInt ("u", myUserId);
- Message msg = new Message(Command.BattleExit, data);
- EnSendQueue(msg);
- }
- private void OnExitBattle(string cmd, ISFSObject data)
- {
- int userId = data.GetInt ("u");
- if(userId == myUserId)
- {
- ToMenu ();
- }
- }
- public void ToMenu()
- {
- BattleController.battleType = BattleController.BattleType.Menu;
- LoadingPanel panel = LoadingPanel.Show ();
- LoadingPanel.Increase (0.1f);
- panel.ReachTargetProgress.AddListener (()=>{
- LoadingPanel.LoadScene(Config.Scene.Battle.ToString());
- });
- }
-
- public void ClanInit()
- {
- ISFSObject data = new SFSObject ();
- Message msg = new Message (Command.ClanInit, data);
- EnSendQueue (msg);
- }
- private void OnClanInit(string cmd, ISFSObject data)
- {
- }
- private void OnClanOnline(string cmd, ISFSObject data)
- {
- if(data.ContainsKey("a"))
- InviteManager.GetInstance ().SetData (data.GetSFSArray ("a"));
- if (data.ContainsKey ("i")) {
- InviteManager.GetInstance ().Add (StringUtil.ToInt (data.GetUtfString ("i")), InviteData.State.Online);
- InviteManager.GetInstance ().Sort ();
- }
- }
- private void OnClanOffline(string cmd, ISFSObject data)
- {
- InviteManager.GetInstance ().Offline (StringUtil.ToInt (data.GetUtfString("i")));
- }
- private void OnClanBattle(string cmd, ISFSObject data)
- {
- int id = StringUtil.ToInt (data.GetUtfString("i"));
- InviteManager.GetInstance ().Battle (id);
- }
- public void ClanMessage(string content)
- {
- ISFSObject data = new SFSObject ();
- data.PutInt ("u", myUserId);
- data.PutUtfString ("m", content);
- Message msg = new Message (Command.ClanMessage, data);
- EnSendQueue (msg);
- }
- private void OnClanMessage(string cmd, ISFSObject data)
- {
- if (!CheckError (cmd, data)) {
- int userId = data.GetInt ("u");
- string content = data.GetUtfString ("m");
- ChatManager.GetInstance ().AddClanMsg (userId, content);
- }
- }
- public void ClanJoin()
- {
- if (Session.GetInstance ().myUserData.clanId > 0) {
- LocalToRemote ();
- ISFSObject data = new SFSObject ();
- data.PutInt (UserSFSObjectLabel.CLAN, Session.GetInstance().myUserData.clanId);
- Message msg = new Message (Command.ClanJoin, data);
- EnSendQueue (msg);
- }
- }
- private void OnClanJoin(string cmd, ISFSObject data)
- {
- Ready ();
- }
- public void ClanLeft()
- {
- Message msg = new Message (Command.ClanLeft, new SFSObject ());
- EnSendQueue (msg);
- }
- private void OnClanLeft(string cmd, ISFSObject data)
- {
- List<Player> list = battleSession.GetPlayerList ();
- for(int i=0; i<list.Count; i++)
- {
- Player player = list [i];
- if(player.isMe || player.GetHero().GetCraft() == null)
- continue;
- battleSession.GetBattleController ().DealDeath (player.userId, player.GetHero().GetCraft().id, 0);
- }
- }
- public void TeamInvite(int id)
- {
- ISFSObject data = new SFSObject ();
- data.PutUtfString ("t", id.ToString());
- Message msg = new Message (Command.TeamInvite, data);
- EnSendQueue (msg);
- }
- private void OnTeamInvite(string cmd, ISFSObject data)
- {
- int id = StringUtil.ToInt(data.GetUtfString ("t"));
- string nick = UserCache.GetNick (id);
- string info = Language.GetStr ("Invite", "teamInviteConfirm").Replace ("%NICK%", nick);
- AlertPanel.Show (info, AlertPanel.YES|AlertPanel.NO, (AlertCloseEvent evt)=>{
- if(evt.detail == AlertPanel.YES)
- {
- TeamJoin(id);
- }
- });
- }
- public void TeamJoin(int id)
- {
- ISFSObject data = new SFSObject ();
- data.PutUtfString ("t", id.ToString());
- Message msg = new Message (Command.TeamJoin, data);
- EnSendQueue (msg);
- }
- private void OnTeamJoin(string cmd, ISFSObject data)
- {
-
- }
- public void TeamLeft()
- {
- ISFSObject data = new SFSObject ();
- Message msg = new Message (Command.TeamLeft, data);
- EnSendQueue (msg);
- }
- private void OnTeamLeft(string cmd, ISFSObject data)
- {
-
- }
- public void TeamKick(int id)
- {
- ISFSObject data = new SFSObject ();
- data.PutUtfString ("t", id.ToString());
- Message msg = new Message (Command.TeamKick, data);
- EnSendQueue (msg);
- }
- private void OnTeamKick(string cmd, ISFSObject data)
- {
-
- }
- private void OnTeamState(string cmd, ISFSObject data)
- {
- int leader = StringUtil.ToInt (data.GetUtfString (UserSFSObjectLabel.TEAM_LEADER_ID));
- if (data.ContainsKey (UserSFSObjectLabel.TEAM)) {
- InviteManager.GetInstance().TeamState(leader, data.GetSFSArray(UserSFSObjectLabel.TEAM));
- }
- else{
- InviteManager.GetInstance().TeamState(leader, null);
- }
- }
- public void Dispose()
- {
- Disconnect();
- }
- }
|