Exemple #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();
            }
        }
 public static void SpawnCores(MyCubeGrid grid, KothConfig config)
 {
     if (grid != null)
     {
         Sandbox.ModAPI.IMyGridTerminalSystem gridTerminalSys = MyAPIGateway.TerminalActionsHelper.GetTerminalSystemForGrid(grid);
         MyDefinitionId rewardItem             = getRewardItem(config);
         Sandbox.ModAPI.IMyTerminalBlock block = gridTerminalSys.GetBlockWithName(config.LootBoxTerminalName);
         if (block != null && rewardItem != null)
         {
             Log.Info("Should spawn item");
             MyItemType itemType = new MyInventoryItemFilter(rewardItem.TypeId + "/" + rewardItem.SubtypeName).ItemType;
             block.GetInventory().AddItems((MyFixedPoint)config.RewardAmount, (MyObjectBuilder_PhysicalObject)MyObjectBuilderSerializer.CreateNewObject(rewardItem));
         }
         else
         {
             Log.Info("Cant spawn item");
         }
         return;
     }
 }
Exemple #3
0
        private static void FillContainer()
        {
            if (count == 16)
            {
                SendMessageTemp("PvP Event", "Event is over", Color.Red);
                bTimer.Close();
                return;
            }
            count++;
            MyCubeGrid TechGrid = null;
            ConcurrentBag <MyGroups <MyCubeGrid, MyGridPhysicalGroupData> .Group> groups = GridFinder.FindGridGroup(gridName);

            Parallel.ForEach(MyCubeGridGroups.Static.Physical.Groups, group =>
            {
                foreach (MyGroups <MyCubeGrid, MyGridPhysicalGroupData> .Node groupNodes in group.Nodes)
                {
                    MyCubeGrid grid = groupNodes.NodeData;
                    //does the grid have the same name as the input
                    bool found = false;

                    foreach (VRage.Game.ModAPI.IMySlimBlock block in grid.GetBlocks())
                    {
                        if (block != null && block.BlockDefinition.Id.SubtypeName.Contains("PrizeboxD") && grid.DisplayName.Equals(gridName))
                        {
                            TechGrid = grid;
                            found    = true;
                        }
                    }
                    if (!found)
                    {
                        continue;
                    }
                    break;
                }
            });
            if (TechGrid != null)
            {
                Sandbox.ModAPI.IMyTerminalBlock container = MyAPIGateway.TerminalActionsHelper.GetTerminalSystemForGrid(TechGrid).GetBlockWithName("Tech Container") as IMyTerminalBlock;
                Random random = new Random();
                int    num    = random.Next(100);
                if (num <= 1)
                {
                    if (!billion)
                    {
                        container.GetInventory().AddItems(VRage.MyFixedPoint.DeserializeStringSafe("50000000"), new MyObjectBuilder_PhysicalObject()
                        {
                            SubtypeName = "SpaceCredit"
                        });
                        SendMessageTemp("PvP " + gridName, "50 Million SC.", Color.Red);

                        billion = true;
                    }
                    else
                    {
                        container.GetInventory().AddItems(VRage.MyFixedPoint.DeserializeStringSafe("10000000"), new MyObjectBuilder_PhysicalObject()
                        {
                            SubtypeName = "SpaceCredit"
                        });
                        SendMessageTemp("PvP " + gridName, "10 Million SC.", Color.Red);
                        return;
                    }
                    return;
                }
                if (num <= 50)
                {
                    container.GetInventory().AddItems(VRage.MyFixedPoint.DeserializeStringSafe("10000000"), new MyObjectBuilder_PhysicalObject()
                    {
                        SubtypeName = "SpaceCredit"
                    });
                    SendMessageTemp("PvP " + gridName, "10 Million SC.", Color.Red);
                    return;
                }
                else
                {
                    num = random.Next(100);
                    if (num <= 10)
                    {
                        int num2 = random.Next(100);
                        if (num2 <= 10)
                        {
                            container.GetInventory().AddItems(VRage.MyFixedPoint.DeserializeStringSafe("50"), new MyObjectBuilder_Component()
                            {
                                SubtypeName = "Tech8x"
                            });
                            SendMessageTemp("PvP " + gridName, "50 Exotic", Color.Red);
                        }
                        else
                        {
                            container.GetInventory().AddItems(VRage.MyFixedPoint.DeserializeStringSafe("10"), new MyObjectBuilder_Component()
                            {
                                SubtypeName = "Tech8x"
                            });
                            SendMessageTemp("PvP " + gridName, "10 Exotic", Color.Red);
                        }
                        return;
                    }
                    if (num <= 30)
                    {
                        int num2 = random.Next(100);
                        if (num2 <= 40)
                        {
                            container.GetInventory().AddItems(VRage.MyFixedPoint.DeserializeStringSafe("75"), new MyObjectBuilder_Component()
                            {
                                SubtypeName = "Tech4x"
                            });
                            SendMessageTemp("PvP " + gridName, "75 Rare", Color.Red);
                        }
                        else
                        {
                            container.GetInventory().AddItems(VRage.MyFixedPoint.DeserializeStringSafe("25"), new MyObjectBuilder_Component()
                            {
                                SubtypeName = "Tech4x"
                            });
                            SendMessageTemp("PvP " + gridName, "25 Rare", Color.Red);
                        }
                        return;
                    }
                    if (num <= 100)
                    {
                        int num2 = random.Next(100);
                        if (num2 <= 50)
                        {
                            container.GetInventory().AddItems(VRage.MyFixedPoint.DeserializeStringSafe("100"), new MyObjectBuilder_Component()
                            {
                                SubtypeName = "Tech2x"
                            });
                            SendMessageTemp("PvP " + gridName, "100 Common", Color.Red);
                        }
                        else
                        {
                            container.GetInventory().AddItems(VRage.MyFixedPoint.DeserializeStringSafe("50"), new MyObjectBuilder_Component()
                            {
                                SubtypeName = "Tech2x"
                            });
                            SendMessageTemp("PvP " + gridName, "50 Common", Color.Red);
                        }
                        return;
                    }
                }
            }
        }