コード例 #1
0
        public void DeliverContract()
        {
            Contract      contract        = TruckingPlugin.getActiveContract(Context.Player.SteamUserId);
            StringBuilder contractDetails = new StringBuilder();

            if (contract != null)
            {
                Vector3D coords   = contract.GetDeliveryLocation().Coords;
                float    distance = Vector3.Distance(coords, Context.Player.Character.PositionComp.GetPosition());
                if (distance <= 1000)
                {
                    List <VRage.ModAPI.IMyEntity> l = new List <VRage.ModAPI.IMyEntity>();

                    BoundingSphereD sphere = new BoundingSphereD(Context.Player.Character.PositionComp.GetPosition(), 1000);
                    l = MyAPIGateway.Entities.GetEntitiesInSphere(ref sphere);

                    Dictionary <MyDefinitionId, int> itemsToRemove = new Dictionary <MyDefinitionId, int>();
                    int pay = 0;
                    foreach (ContractItems item in contract.getItemsInContract())
                    {
                        if (MyDefinitionId.TryParse("MyObjectBuilder_" + item.ItemType, item.SubType, out MyDefinitionId id))
                        {
                            itemsToRemove.Add(id, item.AmountToDeliver);
                            pay += item.AmountToDeliver * item.GetPrice();
                        }
                        else
                        {
                            Context.Respond("Theres an error in the config for this item, report in a ticket " + id.SubtypeName + " " + id.TypeId);
                        }
                    }

                    foreach (IMyEntity entity in l)
                    {
                        if (entity is MyCubeGrid grid)
                        {
                            List <VRage.Game.ModAPI.IMyInventory> inventories = TakeTheItems.GetInventories(grid);
                            if (FacUtils.IsOwnerOrFactionOwned(grid, Context.Player.IdentityId, true))
                            {
                                if (TakeTheItems.ConsumeComponents(inventories, itemsToRemove, Context.Player.SteamUserId))
                                {
                                    MyBankingSystem.ChangeBalance(Context.Player.Identity.IdentityId, pay);
                                    Database.RemoveContract(Context.Player.SteamUserId, true, contract, Context.Player.IdentityId);
                                    TruckingPlugin.SendMessage("The Boss", "Contract Complete, Payment delivered to bank account.", Color.Purple, Context.Player.SteamUserId);
                                    return;
                                }
                            }
                        }
                    }
                    Context.Respond("Could not find owned grid in vicinity with the required items.", "The Boss");
                }
                else
                {
                    Context.Respond("You arent close enough to the delivery point! Must be within 1km of signal", "The Boss");
                }
            }
            else
            {
                Context.Respond("You dont have an active contract.", "The Boss");
            }
        }
コード例 #2
0
        public override void Update()
        {
            try
            {
                //slow this shit down so it doesnt lag out console, 32 is fine but i dont think it needs to check that often
                ++this.tick;


                if (this.tick % 128 == 0)
                {
                    if (DateTime.Now >= nextUpdate && config.UsingWhitelist)
                    {
                        nextUpdate = DateTime.Now.AddMinutes(5);
                        Whitelist.Clear();
                        Database.LoadWhitelist();
                    }
                    foreach (MyPlayer onlinePlayer in MySession.Static.Players.GetOnlinePlayers())
                    {
                        MyPlayer playerOnline = onlinePlayer;
                        if (onlinePlayer.Character != null && onlinePlayer?.Controller.ControlledEntity is MyCockpit controller)
                        {
                            MyCubeGrid grid = controller.CubeGrid;
                            if (TruckingPlugin.getActiveContract(onlinePlayer.Id.SteamId) != null)
                            {
                                Contract contract = TruckingPlugin.getActiveContract(onlinePlayer.Id.SteamId);
                                Vector3D coords   = contract.GetDeliveryLocation().Coords;
                                float    distance = Vector3.Distance(coords, onlinePlayer.Character.PositionComp.GetPosition());
                                if (distance <= 300)
                                {
                                    List <VRage.ModAPI.IMyEntity> l = new List <VRage.ModAPI.IMyEntity>();

                                    BoundingSphereD sphere = new BoundingSphereD(onlinePlayer.Character.PositionComp.GetPosition(), 1000);
                                    l = MyAPIGateway.Entities.GetEntitiesInSphere(ref sphere);

                                    Dictionary <MyDefinitionId, int> itemsToRemove = new Dictionary <MyDefinitionId, int>();
                                    int pay = 0;
                                    //calculate the pay since we only show the player the minimum they can get, this could be removed if the pay is made part of the contract
                                    //when its generated and stored in the db, reputation when completed could give a bonus percent
                                    foreach (ContractItems item in contract.getItemsInContract())
                                    {
                                        if (MyDefinitionId.TryParse("MyObjectBuilder_" + item.ItemType, item.SubType, out MyDefinitionId id))
                                        {
                                            itemsToRemove.Add(id, item.AmountToDeliver);
                                            pay += item.AmountToDeliver * item.GetPrice();
                                        }
                                    }


                                    List <VRage.Game.ModAPI.IMyInventory> inventories = TakeTheItems.GetInventories(grid);

                                    if (FacUtils.IsOwnerOrFactionOwned(grid, onlinePlayer.Identity.IdentityId, true) && Vector3.Distance(coords, grid.PositionComp.GetPosition()) <= 300)
                                    {
                                        if (TakeTheItems.ConsumeComponents(inventories, itemsToRemove, onlinePlayer.Id.SteamId))
                                        {
                                            MyBankingSystem.ChangeBalance(onlinePlayer.Identity.IdentityId, pay);
                                            Database.RemoveContract(onlinePlayer.Id.SteamId, true, contract, onlinePlayer.Identity.IdentityId);
                                            TruckingPlugin.SendMessage("The Boss", "Contract Complete, Payment delivered to bank account.", Color.Purple, onlinePlayer.Id.SteamId);
                                            //if (TruckingPlugin.config.DoBonusRewards)
                                            //{
                                            //    List<ContractItems> SortedList = bonusRewards.OrderByDescending(o => o.chance).ToList();
                                            //    Random random = new Random();
                                            //    foreach (ContractItems item in SortedList)
                                            //    {

                                            //        int chance = random.Next(101);
                                            //        if (chance <= item.chance)
                                            //        {

                                            //        }
                                            //    }
                                            //}
                                            return;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                TruckingPlugin.Log.Info("Space trucking error " + ex.ToString());
            }
        }