/// <summary> /// Enable window and start listening for inventory updates /// </summary> /// <param name="itemStorage">reference to player's DynamicItemStorage</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(DynamicItemStorage 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 CurrentOpenStorage.ClientSlotCharacteristic) { ItemSlot playerSlot = slotUI.Key; playerSlot.OnSlotContentsChangeClient.AddListener(OnSlotContentsChangeClient); var slot = Instantiate(SlotPrefab, Vector3.zero, Quaternion.identity, AreaGameObject.transform); slot.transform.localScale = Vector3.one; slot.GetComponent <PlayerExaminationWindowSlot>().SetUp(slotUI.Value, slotUI.Key, this); UISlots.Add(slot); } gameObject.SetActive(true); OnSlotContentsChangeClient(); }
/// <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)); }
/// <summary> /// Reset all components and disable window /// </summary> private void Reset() { playerName.text = string.Empty; playerSpecies.text = string.Empty; playerJob.text = string.Empty; playerStatus.text = string.Empty; additionalInformationsText.text = string.Empty; if (CurrentOpenStorage != null) { foreach (var slotUI in UISlots) { // remove event listener ItemSlot playerSlot = slotUI.GetComponent <PlayerExaminationWindowSlot>().UI_ItemSlot.ItemSlot; playerSlot.OnSlotContentsChangeClient.RemoveListener(OnSlotContentsChangeClient); Destroy(slotUI); } } UISlots.Clear(); CurrentOpenStorage = null; currentEquipment = null; gameObject.SetActive(false); expandedView.SetActive(false); }
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!"); }
/// <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); } }
public void OnInventoryMoveServer(InventoryMove info) { //Wearing if (info.ToSlot?.NamedSlot != null) { ItemStorage = info.ToRootPlayer?.PlayerScript.DynamicItemStorage; if (ItemStorage != null && NamedSlotFlagged.HasFlag( ItemSlot.GetFlaggedSlot(info.ToSlot.NamedSlot.GetValueOrDefault(NamedSlot.outerwear)))) { AddSelf(ItemStorage); return; } } //taking off if (info.FromSlot?.NamedSlot != null) { ItemStorage = info.FromRootPlayer?.PlayerScript.DynamicItemStorage; if (ItemStorage != null && NamedSlotFlagged.HasFlag( ItemSlot.GetFlaggedSlot(info.FromSlot.NamedSlot.GetValueOrDefault(NamedSlot.outerwear)))) { RemoveSelf(ItemStorage); return; } } }
public static NetMessage Send(DynamicItemStorage DIM, GameObject ToWho) { NetMessage msg = new NetMessage { NetIDOfStorage = DIM.netId }; SendTo(ToWho, msg); return(msg); }
} = true; //Only used on the server public override void Awake() { base.Awake(); playerNetworkActions = GetComponent <PlayerNetworkActions>(); playerMove = GetComponent <PlayerMove>(); playerSprites = GetComponent <PlayerSprites>(); registerPlayer = GetComponent <RegisterPlayer>(); dynamicItemStorage = GetComponent <DynamicItemStorage>(); OnConsciousStateChangeServer.AddListener(OnPlayerConsciousStateChangeServer); registerPlayer.AddStatus(this); }
/// <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); }
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); }
/// <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); }
public void CmdRequestItemLabel(GameObject handLabeler, string label) { DynamicItemStorage itemStorage = gameObject.GetComponent <DynamicItemStorage>(); Pickupable handItem = itemStorage.GetActiveHandSlot()?.Item; if (handItem == null) { return; } if (handItem.gameObject != handLabeler) { return; } Chat.AddExamineMsgFromServer(gameObject, "You set the " + handLabeler.Item().InitialName.ToLower() + "s text to '" + label + "'."); handLabeler.GetComponent <HandLabeler>().SetLabel(label); }
} = true; //Only used on the server public override void EnsureInit() { if (init) { return; } init = true; base.EnsureInit(); playerNetworkActions = GetComponent <PlayerNetworkActions>(); playerMove = GetComponent <PlayerMove>(); playerSprites = GetComponent <PlayerSprites>(); registerPlayer = GetComponent <RegisterPlayer>(); dynamicItemStorage = GetComponent <DynamicItemStorage>(); equipment = GetComponent <Equipment>(); playerScript = GetComponent <PlayerScript>(); OnConsciousStateChangeServer.AddListener(OnPlayerConsciousStateChangeServer); registerPlayer.AddStatus(this); }
private void Awake() { playerSprites = GetComponent <PlayerSprites>(); playerNetworkActions = GetComponent <PlayerNetworkActions>(); registerTile = GetComponent <RegisterPlayer>(); playerHealth = GetComponent <PlayerHealthV2>(); pushPull = GetComponent <ObjectBehaviour>(); weaponNetworkActions = GetComponent <WeaponNetworkActions>(); mouseInputController = GetComponent <MouseInputController>(); chatIcon = GetComponentInChildren <ChatIcon>(true); playerMove = GetComponent <PlayerMove>(); playerDirectional = GetComponent <Rotatable>(); DynamicItemStorage = GetComponent <DynamicItemStorage>(); Equipment = GetComponent <Equipment>(); Cooldowns = GetComponent <HasCooldowns>(); PlayerOnlySyncValues = GetComponent <PlayerOnlySyncValues>(); playerCrafting = GetComponent <PlayerCrafting>(); PlayerSync = GetComponent <PlayerSync>(); }
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); } }
/// <summary> /// Adds itself to dynamic storage /// </summary> /// <param name="dynamicItemStorage"></param> public void AddSelf(DynamicItemStorage dynamicItemStorage) { dynamicItemStorage.Add(this); }
/// <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))); }
/// <summary> /// Removes itself from dynamic storage /// </summary> /// <param name="dynamicItemStorage"></param> public void RemoveSelf(DynamicItemStorage dynamicItemStorage) { dynamicItemStorage.Remove(this); }
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; } } } }