コード例 #1
0
        public void BroadcastItemAdd(Pickupable pickupable, Transform containerTransform)
        {
            NitroxId itemId = NitroxEntity.GetId(pickupable.gameObject);

            byte[]   bytes   = SerializationHelper.GetBytesWithoutParent(pickupable.gameObject);
            NitroxId ownerId = InventoryContainerHelper.GetOwnerId(containerTransform);

            ItemData  itemData;
            Plantable plant = pickupable.GetComponent <Plantable>();

            if (plant && plant.currentPlanter)
            {
                // special case: we want to remember the time when the plant was added, so we can simulate growth
                itemData = new PlantableItemData(ownerId, itemId, bytes, DayNightCycle.main.timePassedAsDouble);
            }
            else
            {
                itemData = new ItemData(ownerId, itemId, bytes);
            }

            if (packetSender.Send(new ItemContainerAdd(itemData)))
            {
                Log.Debug($"Sent: Added item {pickupable.GetTechType()} to container {containerTransform.gameObject.GetHierarchyPath()}");
            }
        }
コード例 #2
0
        public override void process(GameObject item, ItemData itemData)
        {
            PlantableItemData plantableData = itemData as PlantableItemData;

            if (plantableData == null)
            {
                // nothing to do; false alarm
                return;
            }
            Plantable plant = item.GetComponent <Plantable>();

            if (plant == null)
            {
                Log.Error($"FixPlantGrowth: Item for Plantable {plantableData.ItemId} is not a Plantable!");
                return;
            }

            GrowingPlant grower = GetGrowingPlant(plant);

            if (grower == null)
            {
                Log.Error($"FixPlantGrowth: Could not find GrowingPlant for Plantable {plantableData.ItemId}!");
                return;
            }


            // time in seconds
            double elapsedGrowthTime = (DayNightCycle.main.timePassedAsDouble - plantableData.PlantedGameTime);

            if (elapsedGrowthTime > grower.growthDuration)
            {
                // should be ready
                Log.Debug($"FixPlantGrowth: Finishing {item.name} {plantableData.ItemId} that has grown for {elapsedGrowthTime} seconds");
                grower.SetProgress(1.0f);
            }
            else
            {
                Log.Debug($"FixPlantGrowth: Growing {item.name} {plantableData.ItemId} that has grown for {elapsedGrowthTime} seconds");
                grower.SetProgress(Convert.ToSingle(elapsedGrowthTime / grower.growthDuration));
            }
        }