123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659 |
- 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)
- {
- 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 Message (Command.SimpleSync, data);
- 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();
- }
- }
|