예제 #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();
            }
        }
예제 #2
0
        void AppendingCustomInfo(Sandbox.ModAPI.IMyTerminalBlock block, StringBuilder stringBuilder)
        {
            try
            {
                CompostGrid gridData = CompostDataStore.Get(block);
                if (gridData.OxygenFarms > 0)
                {
                    stringBuilder
                    .Append("Collecting Organic\n")
                    .Append("- ")
                    .Append(gridData.OxygenFarms)
                    .Append(" working Farms\n");
                }
                if (gridData.CropGrowers > 0)
                {
                    stringBuilder
                    .Append("- ")
                    .Append(gridData.CropGrowers)
                    .Append(" working Crop Grower\n");
                }
                if (gridData.Composts > 1)
                {
                    stringBuilder
                    .Append("- ")
                    .Append((gridData.Composts - 1))
                    .Append(" other Composters\n");
                }
                stringBuilder
                .Append("\n")
                .Append((Config.Instance.OrganicPerOxyenfarmPerSecondMin * gridData.EffectiveFarms * 60).ToString("0.00"))
                .Append(" - ")
                .Append((Config.Instance.OrganicPerOxyenfarmPerSecondMax * gridData.EffectiveFarms * 60).ToString("0.00"))
                .Append(" Organic / Minute from Farms");

                if (gridData.PlayersOnToilet.Count > 0)
                {
                    stringBuilder.Append("\n\nEngineers on Toilet\n");
                    foreach (IMyIdentity id in gridData.PlayersOnToilet)
                    {
                        stringBuilder.Append("- ").Append(id.DisplayName).Append("\n");
                    }
                }
            }
            catch (Exception e)
            {
                MyLog.Default.WriteLine("Biogas: ERROR " + e);
            }
        }