Example #1
0
    protected override void OnDeathActions()
    {
        if (CustomNetworkManager.Instance._isServer)
        {
            ConnectedPlayer player = PlayerList.Instance.Get(gameObject);

            string killerName = null;
            if (LastDamagedBy != null)
            {
                killerName = PlayerList.Instance.Get(LastDamagedBy)?.Name;
            }

            if (killerName == null)
            {
                killerName = "Stressful work";
            }

            string playerName = player?.Name ?? "dummy";
            if (killerName == playerName)
            {
                Chat.AddActionMsgToChat(gameObject, "You committed suicide, what a waste.", $"{playerName} committed suicide.");
            }
            else if (killerName.EndsWith(playerName))
            {
                // chain reactions
                Chat.AddActionMsgToChat(gameObject, $" You screwed yourself up with some help from {killerName}",
                                        $"{playerName} screwed himself up with some help from {killerName}");
            }
            else
            {
                PlayerList.Instance.TrackKill(LastDamagedBy, gameObject);
            }

            //drop items in hand
            if (itemStorage != null)
            {
                Inventory.ServerDrop(itemStorage.GetNamedItemSlot(NamedSlot.leftHand));
                Inventory.ServerDrop(itemStorage.GetNamedItemSlot(NamedSlot.rightHand));
            }

            if (isServer)
            {
                EffectsFactory.BloodSplat(transform.position, BloodSplatSize.large, bloodColor);
                string descriptor = null;
                if (player != null)
                {
                    descriptor = player?.Script?.characterSettings?.PossessivePronoun();
                }

                if (descriptor == null)
                {
                    descriptor = "their";
                }

                Chat.AddLocalMsgToChat($"<b>{playerName}</b> seizes up and falls limp, {descriptor} eyes dead and lifeless...", (Vector3)registerPlayer.WorldPositionServer);
            }

            PlayerDeathMessage.Send(gameObject);
        }
    }
Example #2
0
        private void TryAddMark()
        {
            ItemStorage playerStorage = caster.Script.ItemStorage;

            ItemSlot activeHand = playerStorage.GetActiveHandSlot();

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

            ItemSlot leftHand = playerStorage.GetNamedItemSlot(NamedSlot.leftHand);

            if (leftHand != activeHand && leftHand.IsOccupied)
            {
                AddMark(leftHand.Item);
            }
            ItemSlot rightHand = playerStorage.GetNamedItemSlot(NamedSlot.rightHand);

            if (rightHand != activeHand && rightHand.IsOccupied)
            {
                AddMark(rightHand.Item);
            }

            Chat.AddExamineMsgFromServer(caster, "You aren't holding anything that can be marked for recall!");
        }
Example #3
0
    public bool CheckAccess(GameObject Player)
    {
        // If there isn't any restriction, grant access right away
        if ((int)restriction == 0)
        {
            return(true);
        }


        ItemStorage playerStorage = Player.GetComponent <ItemStorage>();

        //this isn't a player. It could be an npc. No NPC access logic at the moment
        if (playerStorage == null)
        {
            return(false);
        }


        //check if active hand or equipped id cards have access
        if (CheckAccessCard(playerStorage.GetNamedItemSlot(NamedSlot.id).ItemObject))
        {
            return(true);
        }

        return(CheckAccessCard(playerStorage.GetActiveHandSlot().ItemObject));
    }
Example #4
0
    public void PopulateItemStorage(ItemStorage ItemStorage, PopulationContext context)
    {
        foreach (var gameObject in DeprecatedContents)
        {
            var ItemSlot = ItemStorage.GetNextFreeIndexedSlot();
            var spawn    = Spawn.ServerPrefab(gameObject, PrePickRandom: true);
            Inventory.ServerAdd(spawn.GameObject, ItemSlot, IgnoreRestraints:  true);
        }

        if (SlotContents.Count == 0)
        {
            return;
        }

        foreach (var namedSlotPopulatorEntry in SlotContents)
        {
            ItemSlot ItemSlot;
            if (namedSlotPopulatorEntry.UesIndex)
            {
                ItemSlot = ItemStorage.GetIndexedItemSlot(namedSlotPopulatorEntry.IndexSlot);
            }
            else
            {
                ItemSlot = ItemStorage.GetNamedItemSlot(namedSlotPopulatorEntry.NamedSlot);
            }
            if (ItemSlot == null)
            {
                continue;
            }

            var spawn = Spawn.ServerPrefab(namedSlotPopulatorEntry.Prefab, PrePickRandom: true);
            Inventory.ServerAdd(spawn.GameObject, ItemSlot, namedSlotPopulatorEntry.ReplacementStrategy, true);
            Inventory.PopulateSubInventory(spawn.GameObject, namedSlotPopulatorEntry.namedSlotPopulatorEntrys);
        }
    }
Example #5
0
        /// <summary>
        /// Enable window and start listening for inventory updates
        /// </summary>
        /// <param name="itemStorage">reference to player item storage</param>
        /// <param name="visibleName">player's visible name</param>
        /// <param name="species">player's species</param>
        /// <param name="job">player's job</param>
        /// <param name="status">player's status</param>
        /// <param name="additionalInformation">extra information characters can see about this character</param>
        public void ExaminePlayer(ItemStorage itemStorage, string visibleName, string species, string job, string status, string additionalInformation)
        {
            Reset();

            CurrentOpenStorage = itemStorage;
            currentEquipment   = itemStorage.gameObject.GetComponent <Equipment>();

            UpdateStorageUI();

            // display info
            playerName.text    = visibleName;
            playerSpecies.text = species;
            playerJob.text     = job;
            playerStatus.text  = status;

            // display additional informations
            additionalInformationsText.text = additionalInformation;

            // add listeners
            foreach (var slotUI in examinationSlotsUI)
            {
                ItemSlot playerSlot = CurrentOpenStorage.GetNamedItemSlot(slotUI.UI_ItemSlot.NamedSlot);
                playerSlot.OnSlotContentsChangeClient.AddListener(OnSlotContentsChangeClient);
            }

            gameObject.SetActive(true);
        }
Example #6
0
    public override void PopulateItemStorage(ItemStorage toPopulate, PopulationContext context)
    {
        Logger.LogTraceFormat("Populating item storage {0}", Category.Inventory, toPopulate.name);
        foreach (var entry in Entries)
        {
            var slot = toPopulate.GetNamedItemSlot(entry.NamedSlot);
            if (slot == null)
            {
                Logger.LogTraceFormat("Skipping populating slot {0} because it doesn't exist in this itemstorage {1}.",
                                      Category.Inventory, entry.NamedSlot, toPopulate.name);
                continue;
            }

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

            if (entry.Prefab != null)
            {
                var spawn = Spawn.ServerPrefab(entry.Prefab);
                Inventory.ServerAdd(spawn.GameObject, slot);
            }
        }
    }
Example #7
0
    /// <summary>
    /// Returns the slot in storage which is the best fit for the item.
    /// The BestSlots list will be scanned through in order. Returns the
    /// first slot in the BestSlots list for which toCheck has the
    /// indicated trait (ignored if trait is left blank) and can be put into the slot. If none of the BestSlots
    /// will fit this item, returns the first slot in storage which can hold the item.
    /// Returns null if the item cannot fit in any slots in storage.
    /// </summary>
    /// <param name="toCheck"></param>
    /// <param name="storage"></param>
    /// <param name="mustHaveUISlot">if true (default), will only return slots
    /// which are linked to a UI slot</param>
    /// <returns></returns>
    public ItemSlot GetBestSlot(Pickupable toCheck, ItemStorage storage, bool mustHaveUISlot = true)
    {
        if (toCheck == null || storage == null)
        {
            Logger.LogTrace("Cannot get best slot, toCheck or storage was null", Category.Inventory);
            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.Inventory, toCheck);
        }
        else
        {
            //find the best slot
            var best = BestSlots.FirstOrDefault(tsm =>
                                                (!mustHaveUISlot || storage.GetNamedItemSlot(tsm.Slot)?.LocalUISlot != null) &&
                                                Validations.CanFit(storage.GetNamedItemSlot(tsm.Slot), toCheck, side) &&
                                                (tsm.Trait == null || itemAttrs.HasTrait(tsm.Trait)));
            if (best != null)
            {
                return(storage.GetNamedItemSlot(best.Slot));
            }
        }

        Logger.LogTraceFormat("Item {0} did not fit in any BestSlots, thus will" +
                              " be placed in first available slot.", Category.Inventory, 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)));
    }
Example #8
0
 private void EnsureInit()
 {
     if (itemStorage != null)
     {
         return;
     }
     itemStorage = GetComponent <ItemStorage>();
     penSlot     = itemStorage.GetNamedItemSlot(NamedSlot.storage01);
     SetupInitialValues();
 }
    protected override void OnDeathActions()
    {
        if (CustomNetworkManager.Instance._isServer)
        {
            PlayerNetworkActions pna = gameObject.GetComponent <PlayerNetworkActions>();
            PlayerMove           pm  = gameObject.GetComponent <PlayerMove>();

            ConnectedPlayer player = PlayerList.Instance.Get(gameObject);

            string killerName = "Stressful work";
            if (LastDamagedBy != null)
            {
                killerName = PlayerList.Instance.Get(LastDamagedBy).Name;
            }

            string playerName = player.Name ?? "dummy";
            if (killerName == playerName)
            {
                Chat.AddActionMsgToChat(gameObject, "You committed suicide, what a waste.", $"{playerName} committed suicide.");
            }
            else if (killerName.EndsWith(playerName))
            {
                // chain reactions
                Chat.AddActionMsgToChat(gameObject, $" You screwed yourself up with some help from {killerName}",
                                        $"{playerName} screwed himself up with some help from {killerName}");
            }
            else
            {
                PlayerList.Instance.TrackKill(LastDamagedBy, gameObject);
            }

            //drop items in hand
            Inventory.ServerDrop(itemStorage.GetNamedItemSlot(NamedSlot.leftHand));
            Inventory.ServerDrop(itemStorage.GetNamedItemSlot(NamedSlot.rightHand));

            if (isServer)
            {
                EffectsFactory.BloodSplat(transform.position, BloodSplatSize.large, bloodColor);
            }

            PlayerDeathMessage.Send(gameObject);
        }
    }
Example #10
0
    private void Awake()
    {
        ItemStorage = GetComponent <ItemStorage>();
        script      = GetComponent <PlayerScript>();

        clothingItems = new Dictionary <NamedSlot, ClothingItem>();
        foreach (var clothingItem in GetComponentsInChildren <ClothingItem>())
        {
            if (clothingItem.Slot != NamedSlot.none)
            {
                clothingItems.Add(clothingItem.Slot, clothingItem);
            }
        }

        maskSlot = ItemStorage.GetNamedItemSlot(NamedSlot.mask);
        headSlot = ItemStorage.GetNamedItemSlot(NamedSlot.head);
        idSlot   = ItemStorage.GetNamedItemSlot(NamedSlot.id);

        InitInternals();
    }
Example #11
0
        /// <summary>
        /// Checks to see if it can put it in any hand, if it cant it will do nothing meaning the item should just drop.
        /// </summary>
        /// <param name="player"></param>
        private void HandInsert(ItemStorage player)
        {
            ItemSlot activeHand = player.GetActiveHandSlot();

            if (Inventory.ServerAdd(InsertedContainer, activeHand))
            {
                return;
            }
            switch (activeHand.NamedSlot)
            {
            case NamedSlot.leftHand:
                ItemSlot rSlot = player.GetNamedItemSlot(NamedSlot.rightHand);
                Inventory.ServerAdd(InsertedContainer, rSlot);
                break;

            case NamedSlot.rightHand:
                ItemSlot lSlot = player.GetNamedItemSlot(NamedSlot.leftHand);
                Inventory.ServerAdd(InsertedContainer, lSlot);
                break;
            }
        }
Example #12
0
        protected override bool CheckCompletion()
        {
            ItemStorage itemStorage = Owner.body.GetComponent <ItemStorage>();

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

            return(itemStorage.GetNamedItemSlot(NamedSlot.handcuffs).IsEmpty);
        }
Example #13
0
 //Update visible name.
 public void RefreshVisibleName()
 {
     // TODO: Check inventory for head/mask items that hide face - atm just check you are not wearing a mask.
     // needs helmet/hideface trait to be added and checked for. This way, we start with a "face name" our characters might know...
     if (IsGhost || ItemStorage.GetNamedItemSlot(NamedSlot.mask).IsEmpty)
     {
         SyncVisibleName(playerName, playerName);
     }
     else
     {
         SyncVisibleName("Unknown", "Unknown");
     }
 }
    public bool CheckAccess(GameObject Player)
    {
        IDCard      card;
        ItemStorage playerStorage = Player.GetComponent <ItemStorage>();

        //this isn't a player. It could be an npc:
        if (playerStorage == null)
        {
            if ((int)restriction == 0)
            {
                return(true);
            }
            return(false);
        }

        // Check for an ID card
        var idId   = playerStorage.GetNamedItemSlot(NamedSlot.id).ItemObject;
        var handId = playerStorage.GetActiveHandSlot().ItemObject;

        if (idId != null && idId.GetComponent <IDCard>() != null)
        {
            card = idId.GetComponent <IDCard>();
        }
        else if (handId != null &&
                 handId.GetComponent <IDCard>() != null)
        {
            card = handId.GetComponent <IDCard>();
        }
        else
        {
            // If there isn't one, see if we even need one
            if ((int)restriction == 0)
            {
                return(true);
            }
            // If there isn't one and we don't need one, we don't open the door
            return(false);
        }

        // If we have an ID, make sure we have access
        if ((int)restriction == 0)
        {
            return(true);
        }
        if (card.accessSyncList.Contains((int)restriction))
        {
            return(true);
        }
        return(false);
    }
Example #15
0
    public override void PopulateItemStorage(ItemStorage ItemStorage, PopulationContext context)
    {
        //Uses the old contents for now
        foreach (var gameObject in DeprecatedContents)
        {
            var ItemSlot = ItemStorage.GetNextFreeIndexedSlot();
            var spawn    = Spawn.ServerPrefab(gameObject, PrePickRandom: true);
            Inventory.ServerAdd(spawn.GameObject, ItemSlot, IgnoreRestraints:  true);
        }

        if (SlotContents.Count == 0)
        {
            return;
        }

        //Look through the specified slots, and tries to find it on the storage and populates if so,
        //and then attempts recursion
        foreach (var namedSlotPopulatorEntry in SlotContents)
        {
            ItemSlot ItemSlot;
            if (namedSlotPopulatorEntry.UesIndex)
            {
                ItemSlot = ItemStorage.GetIndexedItemSlot(namedSlotPopulatorEntry.IndexSlot);
            }
            else
            {
                ItemSlot = ItemStorage.GetNamedItemSlot(namedSlotPopulatorEntry.NamedSlot);
            }
            if (ItemSlot == null)
            {
                continue;
            }

            var spawn = Spawn.ServerPrefab(namedSlotPopulatorEntry.Prefab, PrePickRandom: true);
            Inventory.ServerAdd(spawn.GameObject, ItemSlot, namedSlotPopulatorEntry.ReplacementStrategy, true);
            Inventory.PopulateSubInventory(spawn.GameObject, namedSlotPopulatorEntry.namedSlotPopulatorEntrys);
        }
    }
    public override void PopulateItemStorage(ItemStorage toPopulate, PopulationContext context)
    {
        Logger.LogTraceFormat("Populating item storage {0}", Category.Inventory, toPopulate.name);
        foreach (var entry in Entries)
        {
            var slot = toPopulate.GetNamedItemSlot(entry.NamedSlot);
            if (slot == null)
            {
                Logger.LogTraceFormat("Skipping populating slot {0} because it doesn't exist in this itemstorage {1}.",
                                      Category.Inventory, entry.NamedSlot, toPopulate.name);
                continue;
            }

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

            entry.SlotPopulator.PopulateSlot(slot, context);
        }
    }
Example #17
0
    public override void PopulateItemStorage(ItemStorage toPopulate, PopulationContext context)
    {
        Logger.LogTraceFormat("Populating item storage {0}", Category.Inventory, toPopulate.name);
        foreach (var entry in Entries)
        {
            var slot = toPopulate.GetNamedItemSlot(entry.NamedSlot);
            if (slot == null)
            {
                Logger.LogTraceFormat("Skipping populating slot {0} because it doesn't exist in this itemstorage {1}.",
                                      Category.Inventory, entry.NamedSlot, toPopulate.name);
                continue;
            }

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

            if (entry.Prefab != null)
            {
                // making exception for jumpsuit/jumpskirt

                if (context.SpawnInfo.CharacterSettings.Clothing == Clothing.JumpSkirt &&
                    entry.NamedSlot == NamedSlot.uniform &&
                    skirtVariant != null)
                {
                    var spawnskirt = Spawn.ServerPrefab(skirtVariant);
                    Inventory.ServerAdd(spawnskirt.GameObject, slot);
                    continue;
                }

                //exceoptions for backpack preference

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

                    switch (context.SpawnInfo.CharacterSettings.Backpack)
                    {
                    case Backpack.Duffle:
                        spawnThing = (duffelVariant != null) ? duffelVariant: entry.Prefab;
                        break;

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

                    default:
                        spawnThing = entry.Prefab;
                        break;
                    }

                    var spawnbackpack = Spawn.ServerPrefab(spawnThing);
                    Inventory.ServerAdd(spawnbackpack.GameObject, slot);
                }

                var spawn = Spawn.ServerPrefab(entry.Prefab);
                Inventory.ServerAdd(spawn.GameObject, slot);
            }
        }
    }
Example #18
0
 private void Awake()
 {
     itemStorage = GetComponent <ItemStorage>();
     penSlot     = itemStorage.GetNamedItemSlot(NamedSlot.storage01);
     SetupInitialValues();
 }
    /// <summary>
    /// Get the item in the player's slot
    /// </summary>
    /// <returns>the gameobject item in the player's slot, null if nothing </returns>
    public GameObject GetActiveItemInSlot(NamedSlot slot)
    {
        var pu = itemStorage.GetNamedItemSlot(slot).Item;

        return(pu?.gameObject);
    }
    /// <summary>
    /// Get the item in the player's active hand
    /// </summary>
    /// <returns>the gameobject item in the player's active hand, null if nothing in active hand</returns>
    public GameObject GetActiveHandItem()
    {
        var pu = itemStorage.GetNamedItemSlot(activeHand).Item;

        return(pu?.gameObject);
    }
    /// <summary>
    /// Get the item in the player's active hand
    /// </summary>
    /// <returns>the gameobject item in the player's active hand, null if nothing in active hand</returns>
    public GameObject GetActiveHandItem()
    {
        var pu = itemStorage.GetNamedItemSlot(activeHand).Item;

        return(pu != null ? pu.gameObject : null);
    }
Example #22
0
        /// <summary>
        /// Actions the server performs when the player dies
        /// </summary>
        protected override void OnDeathActions()
        {
            if (CustomNetworkManager.Instance._isServer)
            {
                ConnectedPlayer player = PlayerList.Instance.Get(gameObject);

                string killerName = null;
                if (LastDamagedBy != null)
                {
                    var lastDamager = PlayerList.Instance.Get(LastDamagedBy);
                    if (lastDamager != null)
                    {
                        killerName = lastDamager.Name;
                        AutoMod.ProcessPlayerKill(lastDamager, player);
                    }
                }

                if (killerName == null)
                {
                    killerName = "stressful work";
                }

                string playerName = player?.Name ?? "dummy";
                if (killerName == playerName)
                {
                    Chat.AddActionMsgToChat(gameObject, "You committed suicide, what a waste.", $"{playerName} committed suicide.");
                }
                else if (killerName.EndsWith(playerName))
                {
                    string themself = null;
                    if (player != null)
                    {
                        themself = player.CharacterSettings?.ThemselfPronoun(player.Script);
                    }
                    if (themself == null)
                    {
                        themself = "themself";
                    }
                    //chain reactions
                    Chat.AddActionMsgToChat(gameObject, $"You screwed yourself up with some help from {killerName}",
                                            $"{playerName} screwed {themself} up with some help from {killerName}");
                }
                else
                {
                    PlayerList.Instance.TrackKill(LastDamagedBy, gameObject);
                }

                //drop items in hand
                if (itemStorage != null)
                {
                    Inventory.ServerDrop(itemStorage.GetNamedItemSlot(NamedSlot.leftHand));
                    Inventory.ServerDrop(itemStorage.GetNamedItemSlot(NamedSlot.rightHand));
                }

                if (isServer)
                {
                    EffectsFactory.BloodSplat(RegisterTile.WorldPositionServer, BloodSplatSize.large, BloodSplatType.red);
                    string their = null;
                    if (player != null)
                    {
                        their = player.CharacterSettings?.TheirPronoun(player.Script);
                    }

                    if (their == null)
                    {
                        their = "their";
                    }

                    Chat.AddLocalMsgToChat($"<b>{player.Name}</b> seizes up and falls limp, {their} eyes dead and lifeless...", gameObject);
                }

                TriggerEventMessage.SendTo(gameObject, EVENT.PlayerDied);
            }
        }