Exemple #1
0
        public void ReloadConfig(string subtype, int min, int max, int price)
        {
            if (DrillPatch.playerWithContract.ContainsKey(Context.Player.IdentityId))
            {
                MiningContract contract = new MiningContract();
                contract.subTypeId     = subtype;
                contract.minimunAmount = min;
                contract.maximumAmount = max;

                ContractHolder holder = new ContractHolder();

                holder.MiningRadius = 50000;

                holder.contract = contract;
                holder.GenerateAmountToMine();

                DrillPatch.playerWithContract[Context.Player.IdentityId].MiningContracts.Add(holder.Id, holder);
            }
            else
            {
                PlayerStorage storage = new PlayerStorage();
                storage.steamId    = Context.Player.SteamUserId;
                storage.reputation = 0;
                MiningContract contract = new MiningContract();
                contract.subTypeId     = subtype;
                contract.minimunAmount = min;
                contract.maximumAmount = max;

                ContractHolder holder = new ContractHolder();

                holder.MiningRadius = 50000;

                holder.contract = contract;
                holder.GenerateAmountToMine();

                storage.MiningContracts.Add(holder.Id, holder);
                DrillPatch.playerWithContract.Add(Context.Player.IdentityId, storage);
            }
        }
        public static void TestPatchMethod(MyDrillBase __instance, MyVoxelMaterialDefinition material,
                                           VRageMath.Vector3 hitPosition,
                                           int removedAmount,
                                           bool onlyCheck)
        {
            if (__instance.OutputInventory != null && __instance.OutputInventory.Owner != null)
            {
                if (__instance.OutputInventory.Owner.GetBaseEntity() is MyShipDrill shipDrill)
                {
                    if (drill == null)
                    {
                        drill = __instance.GetType();
                    }

                    if (string.IsNullOrEmpty(material.MinedOre))
                    {
                        return;
                    }

                    if (!onlyCheck)
                    {
                        long playerId    = 0;
                        bool HasContract = false;
                        foreach (IMyCockpit cockpit in shipDrill.CubeGrid.GetFatBlocks().OfType <IMyCockpit>())
                        {
                            if (cockpit.Pilot != null)
                            {
                                MyCharacter pilot = cockpit.Pilot as MyCharacter;
                                if (playerWithContract.ContainsKey(pilot.GetPlayerIdentityId()))
                                {
                                    PlayerStorage storage = playerWithContract[pilot.GetPlayerIdentityId()];
                                    if (storage.CheckIfInMiningArea(hitPosition, material.MinedOre))
                                    {
                                        playerId    = pilot.GetPlayerIdentityId();
                                        HasContract = true;
                                        break;
                                    }
                                }
                            }
                        }
                        if (!HasContract)
                        {
                            return;
                        }


                        MyObjectBuilder_Ore newObject = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_Ore>(material.MinedOre);
                        newObject.MaterialTypeName = new MyStringHash?(material.Id.SubtypeId);
                        float num = (float)((double)removedAmount / (double)byte.MaxValue * 1.0) * __instance.VoxelHarvestRatio * material.MinedOreRatio;
                        if (!MySession.Static.AmountMined.ContainsKey(material.MinedOre))
                        {
                            MySession.Static.AmountMined[material.MinedOre] = (MyFixedPoint)0;
                        }
                        MySession.Static.AmountMined[material.MinedOre] += (MyFixedPoint)num;
                        MyPhysicalItemDefinition physicalItemDefinition = MyDefinitionManager.Static.GetPhysicalItemDefinition((MyObjectBuilder_Base)newObject);
                        MyFixedPoint             amountItems1           = (MyFixedPoint)(num / physicalItemDefinition.Volume);
                        MyFixedPoint             maxAmountPerDrop       = (MyFixedPoint)(float)(0.150000005960464 / (double)physicalItemDefinition.Volume);


                        MyFixedPoint collectionRatio = (MyFixedPoint)drill.GetField("m_inventoryCollectionRatio", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(__instance);
                        MyFixedPoint b            = amountItems1 * ((MyFixedPoint)1 - collectionRatio);
                        MyFixedPoint amountItems2 = MyFixedPoint.Min(maxAmountPerDrop * 10 - (MyFixedPoint)0.001, b);
                        MyFixedPoint totalAmount  = amountItems1 * collectionRatio - amountItems2;
                        if (playerWithContract[playerId].AddToContractAmount(material.MinedOre, totalAmount.ToIntSafe()))
                        {
                            foreach (ContractHolder contractHolder in playerWithContract[playerId].MiningContracts.Values)
                            {
                                if (contractHolder.contract.subTypeId.Equals(material.MinedOre))
                                {
                                    ShipyardCommands.SendMessage("Big Boss Dave", "Contract progress :" + material.MinedOre + " " + contractHolder.minedAmount + " / " + contractHolder.amountToMine, Color.Gold, (long)MySession.Static.Players.TryGetSteamId(playerId));
                                }
                            }
                        }
                    }
                }
                else
                {
                    return;
                }
            }
        }