/// <summary> /// Chooses a character for the match /// </summary> /// <param name="cid"></param> /// <param name="r"></param> /// <returns></returns> public bool Choose(int cid, UDPPacket r = null) { if (r == null) { // if the user is not logged in or match type is none, restart if (!Account.IsLoggedIn() || cid == 0) { Kill2Live.Restart(); return(false); } Debug.Log("Choosing a character: " + cid.ToString() + " ..."); Event e = Match.self.activeEvent; e.User = Account.GetUser(); e.Me = new Player { Character = cid }; // request string j = JsonConvert.SerializeObject(e); UDP.Request(new UDPPacket { Service = UDPService.Match, Action = UDPAction.Choose, Request = j, }); return(false); } else { if (r.Error != 0 || r.Response == null) { UIMessageGlobal.Open(Language.v["choosefailed"], Language.v["choosefaileddesc"]); Debug.LogWarning(r.ToString()); return(false); } Debug.Log("Chosen: " + r.Response); Event e = JsonConvert.DeserializeObject <Event>(r.Response); Match.self.activeEvent.Me.Character = e.Me.Character; UIPlayers.Set(Account.GetUser().Nickname, e.Me.Character); // TODO update ui uiChoose.SetActive(false); return(true); } }
public bool Leave(UDPPacket r = null, bool quit = false) { if (r == null) { // if the user is not logged in, restart if (!Account.IsLoggedIn()) { if (!quit) { Kill2Live.Restart(); } return(false); } Debug.Log("Leaving the match..."); Reset(); uiPlay.SetActive(false); uiJoin.SetActive(true); Event e = new Event { User = Account.GetUser(), }; // request string j = JsonConvert.SerializeObject(e); UDP.Request(new UDPPacket { Service = UDPService.Match, Action = UDPAction.Leave, Request = j, }); return(false); } else { if (r.Error != 0) { if (r.Error >= (int)ServiceError.MatchUnknown) { UIMessageGlobal.Open(Language.v["leavefailed"], Language.v["leavefaileddesc"]); Debug.LogWarning(r.ToString()); } return(false); } return(true); } }
/// <summary> /// Find and join into a game. /// </summary> /// <param name="type"></param> /// <param name="r"></param> public bool Join(MatchType typ = MatchType.None, UDPPacket r = null) { if (r == null) { // if the user is not logged in or match type is none, restart if (!Account.IsLoggedIn()) { Kill2Live.Restart(); return(false); } Debug.Log("Finding a match for " + typ.ToString() + " ..."); Event e = new Event { User = Account.GetUser(), M = new Game { Typ = typ, } }; // request string j = JsonConvert.SerializeObject(e); UDP.Request(new UDPPacket { Service = UDPService.Match, Action = UDPAction.Join, Request = j, }); return(false); } else { if (r.Error != 0) { if (r.Error == (int)ServiceError.AlreadyJoined) { // continue // no return here because of this situation } else if (r.Error >= (int)ServiceError.MatchUnknown) { UIMessageGlobal.Open(Language.v["joinfailed"], Language.v["joinfaileddesc"]); Debug.LogWarning(r.ToString()); return(false); } } Debug.Log("Joining: " + r.Response); Event e = JsonConvert.DeserializeObject <Event>(r.Response); if (e.M.Typ == MatchType.None) { return(false); } activeEvent = e; if (e.M.Status == MatchStatus.Reserved) // still creating a match { if (!refreshing) { refreshing = true; InvokeRepeating("PlayersLoop", 0f, refresh); } } else { if (e.M.Status == MatchStatus.Ready || e.M.Status == MatchStatus.Play) { Players(); } else if (e.M.Status == MatchStatus.End || e.M.Status == MatchStatus.Released) { activeEvent = null; UIPlayers.Clear(); return(false); } } return(true); } }