Exemplo n.º 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");
            }
        }
Exemplo n.º 2
0
        public static Boolean StorePatchMethod(MyStoreBlock __instance, long id, int amount, long targetEntityId, MyPlayer player, MyAccountInfo playerAccountInfo)
        {
            MyStoreItem storeItem = (MyStoreItem)null;
            bool        proceed   = false;

            foreach (MyStoreItem playerItem in __instance.PlayerItems)
            {
                MyCubeGrid grid = __instance.CubeGrid;
                if (FacUtils.GetFactionTag(FacUtils.GetOwner(grid)) != null && FacUtils.GetFactionTag(FacUtils.GetOwner(grid)).Length > 3 && TruckingPlugin.config.NPCGridContracts)
                {
                    proceed = true;
                }
                if (!grid.Editable || !grid.DestructibleBlocks)
                {
                    proceed = true;
                }

                if (__instance.DisplayNameText != null && __instance.DisplayNameText.ToLower().Contains("hauling contracts") && proceed)
                {
                    if (playerItem.Id == id)
                    {
                        storeItem = playerItem;
                        break;
                    }
                }
            }
            //this does things
            if (storeItem != null && proceed)
            {
                if (MyBankingSystem.GetBalance(player.Identity.IdentityId) >= storeItem.PricePerUnit)
                {
                    //if it cant generate a contract, return false
                    if (!TruckingPlugin.GenerateContract(player.Id.SteamId, player.Identity.IdentityId))
                    {
                        return(false);
                    }
                    else
                    {
                        //do the money transfers then return false so the item stays in the store
                        MyBankingSystem.ChangeBalance(player.Identity.IdentityId, (storeItem.PricePerUnit * -1));
                        MyBankingSystem.ChangeBalance(__instance.OwnerId, storeItem.PricePerUnit);
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }
            return(true);
        }
Exemplo n.º 3
0
 public static bool IsOwnerOrFactionOwned(MyCubeGrid grid, long playerId, bool doFactionCheck)
 {
     if (grid.BigOwners.Contains(playerId))
     {
         return(true);
     }
     else
     {
         if (!doFactionCheck)
         {
             return(false);
         }
         long ownerId = GetOwner(grid);
         //check if the owner is a faction member, i honestly dont know the difference between grid.BigOwners and grid.SmallOwners
         return(FacUtils.InSameFaction(playerId, ownerId));
     }
 }
Exemplo n.º 4
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());
            }
        }