public void OnPlayerCardAction() { // TODO - EXAMPLE var playerIdJson = "35215"; var cardId = "2414"; var actionJson = "USE"; if (CurrentSession.FindPlayerById(playerIdJson, out var player) && player.FindInHandCardById(playerIdJson, out var card)) { var actionCommand = AssistanceFunctions.GetEnumByName <CardAction.Command>(actionJson); switch (actionCommand) { case CardAction.Command.USE: card.Use(player); break; case CardAction.Command.ACTIVATED_USE: card.ActivatedUse(player); break; case CardAction.Command.EXCHANGE: card.Exchange(player); break; default: throw new ArgumentOutOfRangeException(); } //CurrentSession.LocalPlayerData.CompleteMove(); CheckEndMove(); Events.OnPlayerAction.TriggerEvents(); } }
public static CardTypeOwnMoneyEffect Deserialize(string json) { var res = JsonConvert.DeserializeObject <CardTypeOwnMoneyEffectJson>(json); return(new CardTypeOwnMoneyEffect( res.playerDirection.Select(AssistanceFunctions.GetEnumByName <PlayerDirection>).ToArray(), AssistanceFunctions.GetEnumByName <CommonCardData.CardType>(res.cardType), Convert.ToInt32(res.currentMoneyBonus))); }
public static ScienceEffect Deserialize(string json) { var res = JsonConvert.DeserializeObject <ScienceEffectJson>(json); return(new ScienceEffect((new Resource.ScienceItem() { Amount = Convert.ToInt32(res.scienceInfo.price), Currency = AssistanceFunctions.GetEnumByName <Resource.Science>(res.scienceInfo.currency) }))); }
public static ProductionCardEffect Deserialize(string json) { var res = JsonConvert.DeserializeObject <ProductionEffectJson>(json); return(new ProductionCardEffect(res.actionInfo.Select(info => new Resource.CurrencyItem { Amount = Convert.ToInt32(info.price), Currency = AssistanceFunctions.GetEnumByName <Resource.CurrencyProducts>(info.currency) }).ToArray())); }
public void OnCreateLobby(CreationLobbyInfo lobbyInfo) { _lobbies.Add(new Lobby(lobbyInfo.lobbyId, new UserData(lobbyInfo.ownerInfo.playerId, lobbyInfo.ownerInfo.playerName, AssistanceFunctions.GetEnumByName <UserData.ReadyState>(lobbyInfo.ownerInfo.state)), new GameSettings(lobbyInfo.lobbyName, Int32.Parse(lobbyInfo.maxPlayers), Int32.Parse(lobbyInfo.moveTime)), lobbyInfo.connectedUsers.Select(user => new UserData(user.playerId, user.playerName, AssistanceFunctions.GetEnumByName <UserData.ReadyState>(user.state))))); Debug.Log($"Lobby was created. Now there are {_lobbies.Count} lobbies"); Events.OnCreateLobby.TriggerEvents(); }
public void OnGetLobbyList(CreationLobbyInfo[] lobbyInfo) { for (int i = 0; i < lobbyInfo.Length; i++) { _lobbies.Add(new Lobby(lobbyInfo[i].lobbyId, new UserData(lobbyInfo[i].ownerInfo.playerId, lobbyInfo[i].ownerInfo.playerName, AssistanceFunctions.GetEnumByName <UserData.ReadyState>(lobbyInfo[i].ownerInfo.state)), new GameSettings(lobbyInfo[i].lobbyName, Int32.Parse(lobbyInfo[i].maxPlayers), Int32.Parse(lobbyInfo[i].moveTime)), lobbyInfo[i].connectedUsers.Select(user => new UserData(user.playerId, user.playerName, AssistanceFunctions.GetEnumByName <UserData.ReadyState>(user.state))))); } Debug.Log($"{_lobbies.Count} lobbies were created"); Events.OnGetLobbyListToLobby.TriggerEvents(); }
public void OnPlayerTradeAction() { // TODO - EXAMPLE var playerIdJson = "35215"; var directionJson = "LEFT"; var currencyJson = "WOOD"; if (CurrentSession.FindPlayerById(playerIdJson, out var player)) { var neighborDirection = AssistanceFunctions.GetEnumByName <PlayerDirection>(directionJson); var currency = AssistanceFunctions.GetEnumByName <Resource.CurrencyProducts>(currencyJson); CurrentSession.Trade(player, neighborDirection, currency); // TODO Events.OnTradeAction.TriggerEvents(); } }
protected override void OnTextMessageReceived(string text) { var result = GameJsonReceiver.Instance.Deserialize(text); var type = AssistanceFunctions.GetEnumByNameUsual <GameMessageType>(result.type); switch (type) { case GameMessageType.init: //var cardType = AssistanceFunctions.GetEnumByNameUsual<CardType>(result.results.cards[].type); //GameManager.Instance.Init(result.results.initInfo); break; case GameMessageType.start: //GameManager.Instance.Start(result.results.startInfo); break; case GameMessageType.cardUse: //GameManager.Instance.On break; case GameMessageType.wonderUse: //GameManager.Instance.On break; case GameMessageType.move: //GameManager.Instance.On break; case GameMessageType.newEpoch: break; case GameMessageType.turnEnd: break; case GameMessageType.endGameScore: //GameManager.Instance.On break; default: break; } }
protected override void OnTextMessageReceived(string text) { var result = LobbyJsonReceiver.Instance.Deserialize(text); var type = AssistanceFunctions.GetEnumByNameUsual <LobbyType>(result.type); switch (type) { case LobbyType.connect: LobbyManager.Instance.OnUserConnectToLobby(result.results.lobbyId, result.results.playerId); break; case LobbyType.disconnect: LobbyManager.Instance.OnUserDisconnectFromLobby(result.results.lobbyId, result.results.playerId); break; case LobbyType.create: LobbyManager.Instance.OnCreateLobby(result.results.lobbyId, result.results.ownerInfo.ownerId, result.results.ownerInfo.ownerName, result.results.lobbyInfo.lobbyName, Int32.Parse(result.results.lobbyInfo.maxPlayers), Int32.Parse(result.results.lobbyInfo.moveTime)); break; case LobbyType.delete: LobbyManager.Instance.OnDeleteLobby(result.results.lobbyId); break; case LobbyType.start: LobbyManager.Instance.OnStartLobby(result.results.lobbyId); break; case LobbyType.update: LobbyManager.Instance.OnUpdateLobbies(result.results.lobbyId, result.results.playerId, result.results.updateInfo.state); break; default: break; } }
public void OnPlayerWonderCardAction() { // TODO - EXAMPLE var playerIdJson = "35215"; var cardId = "2414"; var actionJson = "BUILD"; if (CurrentSession.FindPlayerById(playerIdJson, out var player)) { var actionCommand = AssistanceFunctions.GetEnumByName <WonderCardAction.Command>(actionJson); switch (actionCommand) { case WonderCardAction.Command.BUILD: if (player.FindInHandCardById(playerIdJson, out var card)) { player.WonderCard.Use(player); player.ThrowCard(card); CheckEndMove(); } else { return; // TODO -- error } break; case WonderCardAction.Command.ACTIVATED_USE: player.WonderCard.ActivatedUse(player); break; default: throw new ArgumentOutOfRangeException(); } Events.OnPlayerAction.TriggerEvents(); } }
public void OnUpdateLobbies(string lobbyId, string playerId, string state) { if (FindLobbyById(lobbyId, out var lobby) && lobby.FindUserById(playerId, out var user)) { user.state = AssistanceFunctions.GetEnumByName <UserData.ReadyState>(state); if (user.Id == LocalUserData.Id && lobbyId == lobby.Id) { LocalUserData.state = AssistanceFunctions.GetEnumByName <UserData.ReadyState>(state); } Events.OnUpdateLobbies.TriggerEvents(lobbyId); Debug.Log("IS ALL READY??"); if (lobby.AllUsersReady) { Debug.Log("YES"); //StartLobbyRequest(lobby); // TODO TODO TODO FAKE FakeLobbyServer.Instance.OurFakeStart(lobby); } } }
public CommonCardData BuildCard(string cardJsonInfo) { var card = JsonConvert.DeserializeObject <Root>(cardJsonInfo); var type = AssistanceFunctions.GetEnumByNameUsual <CommonCardData.CardType>(card.type); var costInformation = card.costInfo.Select(info => new Resource.CurrencyItem { Amount = Convert.ToInt32(info.price), Currency = AssistanceFunctions.GetEnumByName <Resource.CurrencyProducts>(info.currency) }).ToArray(); var specs = ((JObject)JsonConvert.DeserializeObject(cardJsonInfo))["specAttributes"].Value <string>(); switch (type) { case CommonCardData.CardType.GUILDS_OWNING: var ownVictoryEffect = CardTypeOwnVictoryEffectJson.Deserialize(specs); return(new GuildsOwningCard(card.id, card.name, type, Convert.ToInt32(card.epoch), costInformation, card.requirementBuildCardId, ownVictoryEffect)); case CommonCardData.CardType.GUILDS_SCIENCE: return(new GuildsScienceCard(card.id, card.name, type, Convert.ToInt32(card.epoch), costInformation, card.requirementBuildCardId, new SelectableScienceEffect())); case CommonCardData.CardType.GUILDS_STRATEGY: var strategyEffect = StrategyEffectJson.Deserialize(specs); return(new GuildsStrategyCard(card.id, card.name, type, Convert.ToInt32(card.epoch), costInformation, card.requirementBuildCardId, strategyEffect)); case CommonCardData.CardType.CIVILIAN: var victoryEffectCivilian = VictoryEffectJson.Deserialize(specs); return(new CivilianCard(card.id, card.name, type, Convert.ToInt32(card.epoch), costInformation, card.requirementBuildCardId, victoryEffectCivilian)); case CommonCardData.CardType.MILITARY: var militaryEffect = MilitaryEffectJson.Deserialize(specs); return(new MilitaryCard(card.id, card.name, type, Convert.ToInt32(card.epoch), costInformation, card.requirementBuildCardId, militaryEffect)); case CommonCardData.CardType.COMMERCIAL_BONUS: var victoryEffect = VictoryEffectJson.Deserialize(specs); var cardTypeOwnMoneyEffect = CardTypeOwnMoneyEffectJson.Deserialize(specs); return(new CommercialBonusCard(card.id, card.name, type, Convert.ToInt32(card.epoch), costInformation, card.requirementBuildCardId, cardTypeOwnMoneyEffect, victoryEffect)); case CommonCardData.CardType.COMMERCIAL_MONEY: var moneyEffect = MoneyEffectJson.Deserialize(specs); return(new CommercialMoneyCard(card.id, card.name, type, Convert.ToInt32(card.epoch), costInformation, card.requirementBuildCardId, moneyEffect)); case CommonCardData.CardType.COMMERCIAL_TRADE: var tradeEffect = TradeEffectJson.Deserialize(specs); return(new CommercialTradeCard(card.id, card.name, type, Convert.ToInt32(card.epoch), costInformation, card.requirementBuildCardId, tradeEffect)); case CommonCardData.CardType.PRODUCTION: var productionEffect = ProductionEffectJson.Deserialize(specs); return(new ProductionCard(card.id, card.name, type, Convert.ToInt32(card.epoch), costInformation, card.requirementBuildCardId, productionEffect)); case CommonCardData.CardType.SCIENTIFIC: var scienceEffect = ScienceEffectJson.Deserialize(specs); return(new ScientificCard(card.id, card.name, type, Convert.ToInt32(card.epoch), costInformation, card.requirementBuildCardId, scienceEffect)); } return(null); }
protected override void OnTextMessageReceived(string text) { try { var result = LobbyJsonReceiver.Instance.Deserialize(text); var type = AssistanceFunctions.GetEnumByNameUsual <LobbyType>(result.type); if (result.IsCorrect) { switch (type) { case LobbyType.getLobby: LobbyManager.Instance.OnGetLobbyList(result.results.lobbyList); break; case LobbyType.connect: LobbyManager.Instance.OnUserConnectToLobby(result.results.connectInfo.lobbyId, result.results.connectInfo.connectedUsers[0].playerId, result.results.connectInfo.connectedUsers[0].playerName, result.results.connectInfo.accessToken); break; case LobbyType.disconnect: LobbyManager.Instance.OnUserDisconnectFromLobby(result.results.disconnectInfo.lobbyId, result.results.disconnectInfo.connectedUsers[0].playerId); break; case LobbyType.create: LobbyManager.Instance.OnCreateLobby(result.results.lobbyInfo); break; case LobbyType.delete: LobbyManager.Instance.OnDeleteLobby(result.results.deleteInfo.lobbyId); break; case LobbyType.start: LobbyManager.Instance.OnStartLobby(result.results.startInfo.lobbyId); break; case LobbyType.update: LobbyManager.Instance.OnUpdateLobbies(result.results.updateInfo.lobbyId, result.results.updateInfo.connectedUsers[0].playerId, result.results.updateInfo.connectedUsers[0].state); break; default: break; } } else { if (result.status == "INVALID_DATA" && type == LobbyType.connect) { LobbyManager.Instance.ConnectError(); } } } catch (Exception e) { Debug.Log($"Can't parse this msg: {text}"); } }