예제 #1
0
 public void BuyCommodity(CommodityData commodity)
 {
     if (shipStatus == 0)
     {
         ShipItem item = GetShipItem(commodity);
         if (item.data.cost <= gameManager.money && item.data.storage <= (shipCap - shipStorage))
         {
             item.AddAmount(1);
             gameManager.money -= item.data.cost;
             shipStorage       += item.data.storage;
             if (textManager.LastMessageInChat() == lastIncrement + " " + item.data.storageSucess)
             {
                 lastIncrement++;
                 textManager.ReplaceMessageInChat(lastIncrement + " " + item.data.storageSucess);
             }
             else
             {
                 textManager.SendMessageToChat(1 + " " + item.data.storageSucess, Message.MessageType.info);
                 lastIncrement = 1;
             }
         }
         else if (item.data.cost > gameManager.money)
         {
             textManager.SendMessageToChat(item.data.storageFailMoney, Message.MessageType.info);
         }
         else if (item.data.storage > (shipCap - shipStorage))
         {
             textManager.SendMessageToChat(item.data.storageFailCap, Message.MessageType.info);
         }
         //item.commodObject.transform.GetChild(1).GetChild(0).GetComponent<TMP_Text>().text = item.Amount.ToString();
         ClearScreen();
         WriteToScreen();
     }
 }
예제 #2
0
        public void CreateShipItem(CommodityData commodityData)
        {
            ShipItem item = new ShipItem(commodityData);

            if (item.data.OreData == null)
            {
                if (item.data.resource == CommodityData.Resource.Food)
                {
                    item.commodObject = Instantiate(shipButtonPrefab, foodObjects.transform);
                    item.commodObject.transform.position = new Vector2(foodObjects.transform.position.x, foodObjects.transform.position.y + (foodObjectCount * -30));
                    foodObjectCount++;
                }
                else if (item.data.resource == CommodityData.Resource.Energy)
                {
                    item.commodObject = Instantiate(shipButtonPrefab, energyObjects.transform);
                    item.commodObject.transform.position = new Vector2(energyObjects.transform.position.x, energyObjects.transform.position.y + (energyObjectCount * -30));
                    energyObjectCount++;
                }
                else
                {
                    item.commodObject = Instantiate(shipButtonPrefab, earthMiscObjects.transform);
                    item.commodObject.transform.position = new Vector2(earthMiscObjects.transform.position.x, earthMiscObjects.transform.position.y + (earthMiscObjectCount * -30));
                    earthMiscObjectCount++;
                }

                item.commodObject.GetComponent <Button>().onClick.RemoveAllListeners();
                item.commodObject.GetComponent <Button>().onClick.AddListener(delegate() { BuyCommodity(item.data); });
                item.commodObject.transform.GetChild(0).GetComponent <TMP_Text>().text = "Buy " + item.data.commodityName;
            }
            else
            {
                if (item.data.resource == CommodityData.Resource.Ore && item.data.type != CommodityData.Type.Building)
                {
                    item.commodObject = Instantiate(shipButtonPrefab, oreObjects.transform);
                    item.commodObject.transform.position = new Vector2(oreObjects.transform.position.x, oreObjects.transform.position.y + (oreObjectsCount * -30));
                    oreObjectsCount++;

                    item.commodObject.GetComponent <Button>().onClick.RemoveAllListeners();
                    item.commodObject.GetComponent <Button>().onClick.AddListener(delegate() { LoadOre(item.data.OreData); });
                    item.commodObject.transform.GetChild(0).GetComponent <TMP_Text>().text = "Load " + item.data.commodityName;
                }
                else
                {
                    item.commodObject = Instantiate(shipButtonPrefab, marsMiscObjects.transform);
                    item.commodObject.transform.position = new Vector2(marsMiscObjects.transform.position.x, marsMiscObjects.transform.position.y + (marsMiscObjectsCount * -30));
                    marsMiscObjectsCount++;
                }
            }



            shipInventory.Add(item);
        }
        //takes in a ship item and loops through the list of commodities then adds the bought amount then clears the shipitem.
        public void AddCommodity(ShipItem shipItem)
        {
            Commodity commodity = GetCommodity(shipItem.data);

            commodity.ChangeAmount(shipItem.Amount);
            shipItem.ClearItem();
            if (commodity.data.resource == CommodityData.Resource.Ore && commodity.data.type == CommodityData.Type.Building)
            {
                gameManager.oreManager.AddOreBuilding(commodity.data, commodity.Amount);
            }
            gameManager.mapManager.AddCommodity(commodity);
        }
예제 #4
0
        public ShipItem GetShipItem(CommodityData commodityData)
        {
            ShipItem shipItem = null;

            for (int i = 0; i < shipInventory.Count; i++)
            {
                if (commodityData == shipInventory[i].data)
                {
                    shipItem = shipInventory[i];
                }
            }
            return(shipItem);
        }