Esempio n. 1
0
        public override void UpdateBeforeSimulation100()
        {
            base.UpdateBeforeSimulation100();

            if (!_init)
            {
                TerminalBlock = Entity as Sandbox.ModAPI.IMyTerminalBlock;
                TerminalBlock.AppendingCustomInfo += AppendingCustomInfo;
                _init = true;
            }
            if (TerminalBlock.IsFunctional)
            {
                CompostGrid gridData     = CompostDataStore.Get(TerminalBlock);
                float       playerAmount = 0;
                if (gridData.LastScan == null || gridData.LastScan < DateTime.Now.AddSeconds(-5))
                {
                    gridData.Refresh();

                    foreach (IMyIdentity identity in gridData.PlayersOnToilet)
                    {
                        IMyPlayer player = Utilities.IdentityToPlayer(identity);
                        if (player == null || player.Character == null || !player.Character.HasInventory)
                        {
                            continue;
                        }
                        IMyInventory inven = player.Character.GetInventory();

                        for (int i = inven.ItemCount - 1; i >= 0; i--)
                        {
                            VRage.Game.ModAPI.Ingame.MyInventoryItem?item = inven.GetItemAt(i);
                            if (!item.HasValue)
                            {
                                continue;
                            }
                            if (item.Value.Type.ToString().Contains("Ore/Organic"))
                            {
                                playerAmount += (float)item.Value.Amount;
                                inven.RemoveItemsAt(i);
                            }
                        }
                    }
                }
                float amount = playerAmount + MyUtils.GetRandomFloat(Config.Instance.OrganicPerOxyenfarmPerSecondMin * gridData.EffectiveFarms * 1.6f, Config.Instance.OrganicPerOxyenfarmPerSecondMax * gridData.EffectiveFarms * 1.6f);
                TerminalBlock.GetInventory().AddItems((VRage.MyFixedPoint)amount, new MyObjectBuilder_Ore()
                {
                    SubtypeName = "Organic"
                });
                TerminalBlock.RefreshCustomInfo();
            }
        }