public void AddItem(GameDataItem item) { if (GameData.Get.Data.Inventory == null) { Data.Inventory = new List <GameDataItem>(); } Data.Inventory.Add(item); }
private bool BuyItem() { ItemDesc item; int diamonds = GameData.Get.Data.Diamonds; if (diamonds < mItemToBuy.Price) { return(false); } item = GameData.Get.GetItem(mItemToBuy.Name); if (item != null) { if (mItemToBuy.Type == TypeItem.Consommable) { GameData.Get.Data.Diamonds = diamonds - mItemToBuy.Price; GameData.Get.UpdateCountItem(item); UpdateDiamonds(); mNextClip = ClipList[1]; } else { MessageBox.SetTextAndShow(ALREADY_BUY); } } else { GameData.Get.Data.Diamonds = diamonds - mItemToBuy.Price; GameDataItem newItem = new GameDataItem(); newItem.ItemDetail = mItemToBuy; newItem.Number = 1; GameData.Get.AddItem(newItem); UpdateDiamonds(); mNextClip = ClipList[1]; } return(true); }
public ItemDesc GetItem(string name) { if (GameData.Get.Data.Inventory == null) { return(null); } GameDataItem item = Data.Inventory.Find(x => x.ItemDetail.Name.Equals(name)); if (item != null) { return(item.ItemDetail); } List <Item> itemsInScene = new List <Item>(GameObject.FindObjectsOfType <Item>()); Item itemInScene = itemsInScene.Find(x => x.ItemDesc.Name.Equals(name)); if (itemInScene != null) { return(itemInScene.ItemDesc); } return(null); }
private void saveTokens() { List <CharacterBehavior> characters = new List <CharacterBehavior>(); List <Item> items = new List <Item>(); foreach (GameObject g in GameObject.FindGameObjectsWithTag("Token")) { if (g.GetComponent <CharacterBehavior>() != null) { characters.Add(g.GetComponent <CharacterBehavior>()); } else if (g.GetComponent <Item>() != null) { items.Add(g.GetComponent <Item>()); } else { Debug.LogError("GameState, saveGameState: Le Token n'est ni un personnage ni un objet"); } } foreach (CharacterBehavior chara in characters) { int row = -1, column = -1; if (chara.caseActuelle != null) { CaseBehavior cell = chara.caseActuelle.GetComponent <CaseBehavior>(); row = cell.row; column = cell.column; } GameDataCharacter newCharacterEntry = new GameDataCharacter(chara.getTokenName(), chara.getOwnerIndex(), row, column, chara.tokenPlace, chara.horsJeu, chara.wounded, chara.freshlyWounded, chara.freshlyHealed, chara.killed, chara.actionPoints); if (chara.cibleToken != null) { if (chara.cibleToken.transform.parent != null) { newCharacterEntry.indexRoomAssociated = chara.cibleToken.transform.parent.GetComponent <HiddenTileBehavior>().tileAssociated.GetComponent <TileBehavior>().index; } else { newCharacterEntry.row = chara.cibleToken.caseActuelle.row; newCharacterEntry.column = chara.cibleToken.caseActuelle.column; } } if (chara.tokenHolder != null) { newCharacterEntry.associatedCharacterName = chara.tokenHolder.getTokenName(); newCharacterEntry.associatedCharacterOwnerIndex = chara.tokenHolder.getOwnerIndex(); } if (chara.tokenTranporte != null) { newCharacterEntry.tokenHeldName = chara.tokenTranporte.GetComponent <Token>().getTokenName(); newCharacterEntry.tokenHeldOwnerIndex = chara.tokenTranporte.GetComponent <Token>().getOwnerIndex(); } charactersData.Add(newCharacterEntry); } foreach (Item item in items) { int row = -1, column = -1; if (item.caseActuelle != null) { CaseBehavior cell = item.caseActuelle.GetComponent <CaseBehavior>(); row = cell.row; column = cell.column; } GameDataItem newItemEntry = new GameDataItem(item.getTokenName(), item.getOwnerIndex(), row, column, item.tokenPlace, item.horsJeu); if (item.cibleToken != null) { if (item.cibleToken.transform.parent != null) { newItemEntry.indexRoomAssociated = item.cibleToken.transform.parent.GetComponent <HiddenTileBehavior>().tileAssociated.GetComponent <TileBehavior>().index; } else { newItemEntry.row = item.cibleToken.caseActuelle.row; newItemEntry.column = item.cibleToken.caseActuelle.column; } } if (item.tokenHolder != null) { newItemEntry.associatedCharacterName = item.tokenHolder.getTokenName(); newItemEntry.associatedCharacterOwnerIndex = item.tokenHolder.getOwnerIndex(); } itemsData.Add(newItemEntry); } }
private List <GameDataItem> buildItemsData() { List <GameDataItem> itemsData = new List <GameDataItem>(); // build revealed items foreach (var token in tokens) { if (token.isItem) { int playerIndex = getPlayerIndex(token.player_id); string name = pickAndAssignToken(playerIndex, token.type); Multi.Logger.Instance.Log("LOG", CreateCoolTokenLogMessage(name, token, "item")); Debug.Assert(name != null); string tokenname = board.ConvertToGame(name); int row = board.ConvertY(token.y); int col = board.ConvertX(token.x); var itemData = new GameDataItem(tokenname, playerIndex, row, col, token.isOnBoard || token.isRemovedFromGame, token.isRemovedFromGame); if (token.isOnTile) { itemData.indexRoomAssociated = board.ConvertTile(token.associatedTileId); } if (token.toBePlaced && gamestate.discoveredRoom != INVALID_INT) { itemData.indexRoomAssociated = board.ConvertTile(gamestate.discoveredRoom); } if (token.isCarried) { board.GetTokenFromId(token.holdingCharacterId, out itemData.associatedCharacterOwnerIndex, out itemData.associatedCharacterName); itemData.associatedCharacterName = board.ConvertToGame(itemData.associatedCharacterName); } if (gamestate.modifiedTokens.ContainsKey(token.id)) { var previousState = gamestate.modifiedTokens[token.id]; if (previousState.isCarried) { board.GetTokenFromId(previousState.holdingCharacterId, out itemData.previousAssociatedCharacterOwnerIndex, out itemData.previousAssociatedCharacterName); itemData.previousAssociatedCharacterName = board.ConvertToGame(itemData.previousAssociatedCharacterName); } else { itemData.previousRow = board.ConvertY(previousState.y); itemData.previousColumn = board.ConvertX(previousState.x); } } itemsData.Add(itemData); } } // build hidden items (in reverse order to take the tokens left by characters loop) for (int i = tokens.Count - 1; i >= 0; --i) { var token = tokens[i]; if (token.isHidden) { int playerIndex = getPlayerIndex(token.player_id); string name = randomPickAndAssignItem(playerIndex); Multi.Logger.Instance.Log("LOG", CreateCoolTokenLogMessage(name, token, "item")); if (name != null) { string tokenname = board.ConvertToGame(name); int row = board.ConvertY(token.y); int col = board.ConvertX(token.x); var itemData = new GameDataItem(tokenname, playerIndex, row, col, token.isOnBoard, token.isRemovedFromGame); if (token.isOnTile) { itemData.indexRoomAssociated = board.ConvertTile(token.associatedTileId); } itemsData.Add(itemData); } } } return(itemsData); }