Exemplo n.º 1
0
        private void TryAddMark()
        {
            DynamicItemStorage playerStorage = caster.Script.DynamicItemStorage;

            ItemSlot activeHand = playerStorage.GetActiveHandSlot();

            if (activeHand.IsOccupied)
            {
                AddMark(activeHand.Item);
                return;
            }

            foreach (var leftHand in playerStorage.GetNamedItemSlots(NamedSlot.leftHand))
            {
                if (leftHand != activeHand && leftHand.IsOccupied)
                {
                    AddMark(leftHand.Item);
                    return;
                }
            }

            foreach (var rightHand in playerStorage.GetNamedItemSlots(NamedSlot.rightHand))
            {
                if (rightHand != activeHand && rightHand.IsOccupied)
                {
                    AddMark(rightHand.Item);
                    return;
                }
            }

            Chat.AddExamineMsgFromServer(caster, "You aren't holding anything that can be marked for recall!");
        }
Exemplo n.º 2
0
        /// <summary>
        /// Calculates the player's total resistance using a base humanoid resistance value,
        /// their health and the items the performer is wearing or holding.
        /// Assumes the player is a humanoid.
        /// </summary>
        /// <param name="voltage">The potential difference across the player</param>
        /// <returns>float resistance</returns>
        protected override float ApproximateElectricalResistance(float voltage)
        {
            // Assume the player is a humanoid
            float resistance = GetNakedHumanoidElectricalResistance(voltage);

            // Give the humanoid extra/less electrical resistance based on what they're holding/wearing
            foreach (var itemSlot in dynamicItemStorage.GetNamedItemSlots(NamedSlot.hands))
            {
                resistance += Electrocution.GetItemElectricalResistance(itemSlot.ItemObject);
            }

            foreach (var itemSlot in dynamicItemStorage.GetNamedItemSlots(NamedSlot.feet))
            {
                resistance += Electrocution.GetItemElectricalResistance(itemSlot.ItemObject);
            }

            // A solid grip on a conductive item will reduce resistance - assuming it is conductive.
            if (dynamicItemStorage.GetActiveHandSlot().Item != null)
            {
                resistance -= 300;
            }

            // Broken skin reduces electrical resistance - arbitrarily chosen at 4 to 1.
            resistance -= 4 * GetTotalBruteDamage();

            // Make sure the humanoid doesn't get ridiculous conductivity.
            if (resistance < 100)
            {
                resistance = 100;
            }
            return(resistance);
        }
Exemplo n.º 3
0
        public bool Initiate(TestRunSO TestRunSO)
        {
            DynamicItemStorage DynamicItemStorage = null;

            if (NotLocalPlayer)
            {
                var Magix = UsefulFunctions.GetCorrectMatrix(MatrixName, WorldPositionOfPlayer);
                var List  = Magix.Matrix.ServerObjects.Get(WorldPositionOfPlayer.ToLocal(Magix).RoundToInt());
                foreach (var registerTile in List)
                {
                    if (registerTile.TryGetComponent <DynamicItemStorage>(out DynamicItemStorage))
                    {
                        break;
                    }
                }
            }
            else
            {
                DynamicItemStorage = PlayerManager.LocalPlayer.GetComponent <DynamicItemStorage>();
            }

            if (DynamicItemStorage == null)
            {
                TestRunSO.Report.AppendLine("Unable to find players inventory");                 //IDK Maybe this should be here maybe not
                return(false);
            }

            var Slot = DynamicItemStorage.GetNamedItemSlots(TargetSlots).First();

            switch (Interaction)
            {
            case InteractionType.Drop:
                Inventory.ServerDrop(Slot);
                break;

            case InteractionType.Destroy:
                Inventory.ServerDespawn(Slot);
                break;

            case InteractionType.TransferTo:
                var TOSlot = DynamicItemStorage.GetNamedItemSlots(TargetSlotsTo).First();
                Inventory.ServerTransfer(Slot, TOSlot);
                break;
            }


            return(true);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Drops items from a player's bodyPart inventory upon dismemberment.
        /// </summary>
        /// <param name="bodyPart">The bodyPart that's cut off</param>
        private void DropItemsOnDismemberment(BodyPart bodyPart)
        {
            DynamicItemStorage storge = HealthMaster.playerScript.DynamicItemStorage;

            void RemoveItemsFromSlot(NamedSlot namedSlot)
            {
                foreach (ItemSlot itemSlot in storge.GetNamedItemSlots(namedSlot))
                {
                    Inventory.ServerDrop(itemSlot);
                }
            }

            //We remove items from both hands to simulate a pain effect, because usually when you lose your arm the other one goes into shock
            if (bodyPart.BodyPartType == BodyPartType.LeftArm ||
                bodyPart.BodyPartType == BodyPartType.RightArm || bodyPart.BodyPartType == BodyPartType.LeftHand ||
                bodyPart.BodyPartType == BodyPartType.RightHand || bodyPart.DeathOnRemoval)
            {
                RemoveItemsFromSlot(NamedSlot.leftHand);
                RemoveItemsFromSlot(NamedSlot.rightHand);
            }
            if (bodyPart.BodyPartType == BodyPartType.RightLeg || bodyPart.BodyPartType == BodyPartType.LeftLeg ||
                bodyPart.BodyPartType == BodyPartType.LeftFoot || bodyPart.BodyPartType == BodyPartType.RightFoot)
            {
                RemoveItemsFromSlot(NamedSlot.feet);
            }

            if (bodyPart.BodyPartType == BodyPartType.Head)
            {
                RemoveItemsFromSlot(NamedSlot.head);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Complete if the player is alive and on one of the escape shuttles and shuttle has
        /// at least one working engine
        /// </summary>
        protected override bool CheckCompletion()
        {
            DynamicItemStorage dynamicItemStorage = Owner.body.GetComponent <DynamicItemStorage>();

            //for whatever reason this is null, give the guy the greentext
            if (dynamicItemStorage == null)
            {
                return(true);
            }

            foreach (var handCuffs in dynamicItemStorage.GetNamedItemSlots(NamedSlot.handcuffs))
            {
                if (handCuffs.IsEmpty)
                {
                    continue;
                }

                //If any hands are cuff then we fail
                return(false);
            }

            return(!Owner.body.playerHealth.IsDead &&
                   ValidShuttles.Any(shuttle => shuttle.MatrixInfo != null &&
                                     (CheckOnShip(Owner.body.registerTile, shuttle.MatrixInfo.Matrix)) && shuttle.HasWorkingThrusters));
        }
Exemplo n.º 6
0
        /// <summary>
        /// Checks to see if a door can be emagged, does checks for BumpInteraction and Hand Interactions.
        /// </summary>
        /// <param name="itemStorage">The player's inventory that may contain the emag</param>
        /// <param name="interaction">If we're calling this from ClosedInteraction() to provide a HandApply</param>
        /// <param name="States">Door process states</param>
        /// <returns>Either hacked or ModuleSignal.Continue</returns>
        private ModuleSignal EmagChecks(DynamicItemStorage itemStorage, HandApply interaction, HashSet <DoorProcessingStates> States)
        {
            if (itemStorage != null)
            {
                try
                {
                    Emag emagInHand = itemStorage.GetActiveHandSlot().Item?.OrNull().gameObject.GetComponent <Emag>()?.OrNull();
                    if (emagInHand != null)
                    {
                        if (interaction != null)
                        {
                            if (emagInHand.UseCharge(interaction))
                            {
                                return(EmagSuccessLogic(States));
                            }
                        }
                        if (emagInHand.UseCharge(gameObject, itemStorage.registerPlayer.PlayerScript.gameObject))
                        {
                            return(EmagSuccessLogic(States));
                        }
                    }

                    foreach (var item in itemStorage.GetNamedItemSlots(NamedSlot.id))
                    {
                        Emag emagInIdSlot = item.Item?.OrNull().gameObject.GetComponent <Emag>()?.OrNull();
                        if (emagInIdSlot == null)
                        {
                            continue;
                        }
                        if (interaction != null)
                        {
                            if (emagInIdSlot.UseCharge(interaction))
                            {
                                return(EmagSuccessLogic(States));
                            }
                        }
                        if (emagInIdSlot.UseCharge(gameObject, itemStorage.registerPlayer.PlayerScript.gameObject))
                        {
                            return(EmagSuccessLogic(States));
                        }
                    }
                }
                catch (NullReferenceException exception)
                {
                    Logger.LogError(
                        $"A NRE was caught in EmagInteractionModule.ClosedInteraction() {exception.Message} \n {exception.StackTrace}",
                        Category.Interaction);
                }
            }

            return(ModuleSignal.Continue);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Checks to see if a door can be emagged, does checks for BumpInteraction and Hand Interactions.
        /// </summary>
        /// <param name="itemStorage">The player's inventory that may contain the emag</param>
        /// <param name="interaction">If we're calling this from ClosedInteraction() to provide a HandApply</param>
        /// <param name="States">Door process states</param>
        /// <returns>Either hacked or ModuleSignal.Continue</returns>
        private ModuleSignal EmagChecks(DynamicItemStorage itemStorage, HandApply interaction,
                                        HashSet <DoorProcessingStates> States)
        {
            if (itemStorage != null)
            {
                Emag emagInHand = itemStorage.OrNull()?.GetActiveHandSlot()?.Item.OrNull()?.gameObject.OrNull()?.GetComponent <Emag>()?.OrNull();
                if (emagInHand != null)
                {
                    if (interaction != null)
                    {
                        if (emagInHand.UseCharge(interaction))
                        {
                            return(EmagSuccessLogic(States));
                        }
                    }

                    if (emagInHand.UseCharge(gameObject, itemStorage.registerPlayer.PlayerScript.gameObject))
                    {
                        return(EmagSuccessLogic(States));
                    }
                }

                foreach (var item in itemStorage.GetNamedItemSlots(NamedSlot.id))
                {
                    Emag emagInIdSlot = item?.Item.OrNull()?.gameObject.GetComponent <Emag>()?.OrNull();
                    if (emagInIdSlot == null)
                    {
                        continue;
                    }
                    if (interaction != null)
                    {
                        if (emagInIdSlot.UseCharge(interaction))
                        {
                            return(EmagSuccessLogic(States));
                        }
                    }

                    if (emagInIdSlot.UseCharge(gameObject, itemStorage.registerPlayer.PlayerScript.gameObject))
                    {
                        return(EmagSuccessLogic(States));
                    }
                }
            }

            return(ModuleSignal.Continue);
        }
Exemplo n.º 8
0
        protected override bool CheckCompletion()
        {
            DynamicItemStorage dynamicItemStorage = Owner.body.GetComponent <DynamicItemStorage>();

            //for whatever reason this is null, give the guy the greentext
            if (dynamicItemStorage == null)
            {
                return(true);
            }

            foreach (var handCuffs in dynamicItemStorage.GetNamedItemSlots(NamedSlot.handcuffs))
            {
                if (handCuffs.IsEmpty)
                {
                    continue;
                }

                //If any hands are cuff then we fail
                return(false);
            }

            return(true);
        }
        public bool Initiate(TestRunSO TestRunSO)
        {
            DynamicItemStorage DynamicItemStorage = null;

            if (NotLocalPlayer)
            {
                var Magix = UsefulFunctions.GetCorrectMatrix(MatrixName, WorldPositionOfPlayer);
                var List  = Magix.Matrix.ServerObjects.Get(WorldPositionOfPlayer.ToLocal(Magix).RoundToInt());
                foreach (var registerTile in List)
                {
                    if (registerTile.TryGetComponent <DynamicItemStorage>(out DynamicItemStorage))
                    {
                        break;
                    }
                }
            }
            else
            {
                DynamicItemStorage = PlayerManager.LocalPlayer.GetComponent <DynamicItemStorage>();
            }

            if (DynamicItemStorage == null)
            {
                TestRunSO.Report.AppendLine("Unable to find players inventory");                 //IDK Maybe this should be here maybe not
                return(false);
            }

            List <ItemSlot> ToCheck = null;

            if (TargetSpecifiedSlot)
            {
                ToCheck = DynamicItemStorage.GetNamedItemSlots(TargetSlots);
            }
            else
            {
                ToCheck = DynamicItemStorage.ServerTotal;
            }

            var OriginalID = ObjectToSearchFor.GetComponent <PrefabTracker>().ForeverID;

            foreach (var slot in ToCheck)
            {
                bool Found = false;
                if (slot.Item != null)
                {
                    var Tracker = slot.Item.GetComponent <PrefabTracker>();
                    if (Tracker != null)
                    {
                        if (Tracker.ForeverID == OriginalID)
                        {
                            Found = true;
                        }
                    }

                    if (IncludeSubInventories && Found == false)
                    {
                        Found = RecursiveSearch(slot.Item.gameObject, OriginalID);
                    }

                    if (Found)
                    {
                        if (Inverse)
                        {
                            TestRunSO.Report.AppendLine(CustomFailedText);
                            TestRunSO.Report.AppendLine($"{ObjectToSearchFor.name} Prefab was found in players inventory ");
                            return(false);
                        }
                        else
                        {
                            return(true);
                        }
                    }
                }
            }

            if (Inverse)             //Nothing was found
            {
                return(true);
            }
            else             //Something wasn't found
            {
                TestRunSO.Report.AppendLine(CustomFailedText);
                TestRunSO.Report.AppendLine($"{ObjectToSearchFor.name} Prefab was not found in players inventory ");
                return(false);
            }
        }
        public virtual void PopulateDynamicItemStorage(DynamicItemStorage toPopulate, PlayerScript PlayerScript, bool useStandardPopulator = true)
        {
            if (useStandardPopulator && toPopulate.StandardPopulator != this)
            {
                toPopulate.StandardPopulator.PopulateDynamicItemStorage(toPopulate, PlayerScript);
            }

            Entries = Entries.OrderBy(entry => entry.NamedSlot).ToList();

            Logger.LogTraceFormat("Populating item storage {0}", Category.EntitySpawn, toPopulate.name);
            foreach (var entry in Entries)
            {
                var slots = toPopulate.GetNamedItemSlots(entry.NamedSlot);
                if (slots.Count == 0)
                {
                    Logger.LogTraceFormat("Skipping populating slot {0} because it doesn't exist in this itemstorage {1}.",
                                          Category.EntitySpawn, entry.NamedSlot, toPopulate.name);
                    continue;
                }

                if (entry.Prefab == null)
                {
                    Logger.LogTraceFormat("Skipping populating slot {0} because Prefab  Populator was empty for this entry.",
                                          Category.EntitySpawn, entry.NamedSlot);
                    continue;
                }

                if (entry.Prefab != null)
                {
                    foreach (var slot in slots)
                    {
                        // making exception for jumpsuit/jumpskirt
                        if (toPopulate.registerPlayer.PlayerScript.characterSettings.ClothingStyle == ClothingStyle.JumpSkirt &&
                            entry.NamedSlot == NamedSlot.uniform &&
                            skirtVariant != null)
                        {
                            var spawnskirt = Spawn.ServerPrefab(skirtVariant, PrePickRandom: true);
                            spawnskirt.GameObject.GetComponent <ItemStorage>()?.SetRegisterPlayer(PlayerScript.registerTile);
                            Inventory.ServerAdd(spawnskirt.GameObject, slot, entry.ReplacementStrategy, true);
                            PopulateSubInventory(spawnskirt.GameObject, entry.namedSlotPopulatorEntrys);
                            break;
                        }

                        //exceoptions for backpack preference

                        if (entry.NamedSlot == NamedSlot.back)
                        {
                            ///SpawnResult spawnbackpack;
                            GameObject spawnThing;

                            switch (toPopulate.registerPlayer.PlayerScript.characterSettings.BagStyle)
                            {
                            case BagStyle.Duffle:
                                spawnThing = (duffelVariant != null) ? duffelVariant : entry.Prefab;
                                break;

                            case BagStyle.Satchel:
                                spawnThing = (satchelVariant != null) ? satchelVariant : entry.Prefab;
                                break;

                            default:
                                spawnThing = entry.Prefab;
                                break;
                            }

                            var spawnbackpack = Spawn.ServerPrefab(spawnThing, PrePickRandom: true);
                            spawnbackpack.GameObject.GetComponent <ItemStorage>()?.SetRegisterPlayer(PlayerScript.registerTile);
                            Inventory.ServerAdd(spawnbackpack.GameObject, slot, entry.ReplacementStrategy, true);
                            PopulateSubInventory(spawnbackpack.GameObject, entry.namedSlotPopulatorEntrys);
                            break;
                        }
                        var spawn = Spawn.ServerPrefab(entry.Prefab, PrePickRandom: true);
                        spawn.GameObject.GetComponent <ItemStorage>()?.SetRegisterPlayer(PlayerScript.registerTile);
                        Inventory.ServerAdd(spawn.GameObject, slot, entry.ReplacementStrategy, true);
                        PopulateSubInventory(spawn.GameObject, entry.namedSlotPopulatorEntrys);
                        break;
                    }
                }
            }
        }
Exemplo n.º 11
0
    /// <summary>
    /// modified for dynamic storage
    /// </summary>
    /// <param name="toCheck"></param>
    /// <param name="storage"></param>
    /// <param name="mustHaveUISlot"></param>
    /// <returns></returns>
    public ItemSlot GetBestSlot(Pickupable toCheck, DynamicItemStorage storage, bool mustHaveUISlot = true)
    {
        if (toCheck == null || storage == null)
        {
            Logger.LogTrace("Cannot get best slot, toCheck or storage was null", Category.PlayerInventory);
            return(null);
        }

        var side      = CustomNetworkManager.IsServer ? NetworkSide.Server : NetworkSide.Client;
        var itemAttrs = toCheck.GetComponent <ItemAttributesV2>();

        if (itemAttrs == null)
        {
            Logger.LogTraceFormat("Item {0} has no ItemAttributes, thus it will be put in the" +
                                  " first available slot.", Category.PlayerInventory, toCheck);
        }
        else
        {
            //find the best slot
            ItemSlot best = null;
            foreach (var tsm in BestSlots)
            {
                if (mustHaveUISlot)
                {
                    bool hasLocalUISlot = false;
                    foreach (var itemSlot in storage.GetNamedItemSlots(tsm.Slot))
                    {
                        if (itemSlot.LocalUISlot != null)
                        {
                            hasLocalUISlot = true;
                        }
                    }

                    if (hasLocalUISlot == false)
                    {
                        continue;
                    }
                }

                bool pass = false;
                foreach (var itemSlot in storage.GetNamedItemSlots(tsm.Slot))
                {
                    if (Validations.CanFit(itemSlot, toCheck, side))
                    {
                        best = itemSlot;
                        pass = true;
                    }
                }
                if (pass == false)
                {
                    continue;
                }

                if (tsm.Trait != null)
                {
                    bool thisitemAttrs = itemAttrs.HasTrait(tsm.Trait);
                    if (thisitemAttrs == false)
                    {
                        continue;
                    }
                }
                return(best);
            }
        }

        Logger.LogTraceFormat("Item {0} did not fit in any BestSlots, thus will" +
                              " be placed in first available slot.", Category.PlayerInventory, toCheck);

        // Get all slots
        var allSlots = storage.GetItemSlots();

        // Filter blaclisted named slots
        var allowedSlots = allSlots.Where((slot) => !slot.NamedSlot.HasValue ||
                                          (slot.NamedSlot.HasValue && !BlackListSlots.Contains(slot.NamedSlot.Value))).ToArray();

        // Select first avaliable
        return(allowedSlots.FirstOrDefault(slot =>
                                           (!mustHaveUISlot || slot.LocalUISlot != null) &&
                                           Validations.CanFit(slot, toCheck, side)));
    }