public void Pool() { IconBackground.Empty(true, false); IconFront.Empty(true, false); IconBackground.SetSpriteSO(DefaultIconBackground, Network: false); this.gameObject.SetActive(false); }
private void RemoveItemFromEquipment() { if (spriteHandler != null) { spriteHandler.Empty(); } if (!InHands && GameObjectReference != null) { // did we take off clothing? var unequippedClothing = GameObjectReference.GetComponent <ClothingV2>(); if (unequippedClothing == null) { //Not clothing, maybe PDA return; } // Unhide the players's slots defined in the clothing's HiddenSlots, as we're removing it. thisPlayerScript.Equipment.obscuredSlots &= ~unequippedClothing.HiddenSlots; if (unequippedClothing) { OnClothingEquipped?.Invoke(unequippedClothing, false); } } GameObjectReference = null; }
/// <summary> /// Uses one charge from the emag, returns true if successful /// </summary> public bool UseCharge(HandApply interaction) { Chat.AddActionMsgToChat(interaction, $"You wave the Emag over the {interaction.TargetObject.ExpensiveName()}'s electrical panel.", $"{interaction.Performer.ExpensiveName()} waves something over the {interaction.TargetObject.ExpensiveName()}'s electrical panel."); if (Charges > 0) { //if this is the first charge taken off, add recharge loop if (Charges >= startCharges) { UpdateManager.Add(RegenerateCharge, rechargeTimeInSeconds); } SyncCharges(Charges, Charges - 1); if (Charges > 0) { spriteHandler.ChangeSprite(ScaleChargesToSpriteIndex()); } else { _ = SoundManager.PlayNetworkedForPlayer(recipient: interaction.Performer, OutOfChargesSFXA, sourceObj: gameObject); spriteHandler.Empty(); } return(true); } return(false); }
public virtual void SetReference(GameObject item) { UpdateReferenceOffset(); if (item == null) { if (spriteHandler != null) { spriteHandler.Empty(); } if (!InHands && GameObjectReference != null) { // did we take off clothing? var unequippedClothing = GameObjectReference.GetComponent <ClothingV2>(); if (unequippedClothing != null) { // Unhide the players's slots defined in the clothing's HiddenSlots, as we're removing it. thisPlayerScript.Equipment.obscuredSlots &= ~unequippedClothing.HiddenSlots; if (unequippedClothing) { OnClothingEquipped?.Invoke(unequippedClothing, false); } } } GameObjectReference = null; // Remove the item from equipment } if (item != null) { GameObjectReference = item; // Add item to equipment if (InHands) { var ItemAttributesV2 = item.GetComponent <ItemAttributesV2>(); var InHandsSprites = ItemAttributesV2?.ItemSprites; SetInHand(InHandsSprites); } else { var equippedClothing = item.GetComponent <ClothingV2>(); equippedClothing?.LinkClothingItem(this); // Set the slots defined in hidesSlots as hidden. //thisPlayerScript.Equipment.obscuredSlots |= equippedClothing.HiddenSlots; // Some items like trash bags / mining satchels can be equipped but are not clothing and do not show on character sprite // But for the others, we call the OnClothingEquipped event. if (equippedClothing) { // call the event of equiped clothing OnClothingEquipped?.Invoke(equippedClothing, true); } } } UpdateReferenceOffset(); }
public void SyncSprite(MountedMonitorState stateOld, MountedMonitorState stateNew) { stateSync = stateNew; if (stateNew == MountedMonitorState.Off) { MonitorSpriteHandler.SetSprite(closedOff); DisplaySpriteHandler.Empty(networked: false); this.TryStopCoroutine(ref blinkHandle); textField.text = ""; } if (stateNew == MountedMonitorState.StatusText) { this.StartCoroutine(BlinkText(), ref blinkHandle); DisplaySpriteHandler.Empty(networked: false); } else if (stateNew == MountedMonitorState.Image) { DisplaySpriteHandler.SetSpriteSO(joeNews, networked: false); this.TryStopCoroutine(ref blinkHandle); textField.text = ""; } else if (stateNew == MountedMonitorState.OpenCabled) { MonitorSpriteHandler.SetSprite(openCabled); } else if (stateNew == MountedMonitorState.NonScrewedPanel) { MonitorSpriteHandler.SetSprite(closedOff); DisplaySpriteHandler.Empty(networked: false); this.TryStopCoroutine(ref blinkHandle); textField.text = ""; } else if (stateNew == MountedMonitorState.OpenEmpty) { MonitorSpriteHandler.SetSprite(openEmpty); } }
public virtual void SetReference(GameObject Item) { UpdateReferenceOffset(); if (Item == null) { if (spriteHandler != null) { spriteHandler.Empty(); } if (!InHands && GameObjectReference != null) { // did we take off clothing? var unequippedClothing = GameObjectReference.GetComponent <ClothingV2>(); if (unequippedClothing) { OnClothingEquiped?.Invoke(unequippedClothing, false); } } GameObjectReference = null; // Remove the item from equipment } if (Item != null) { GameObjectReference = Item; // Add item to equipment if (InHands) { var ItemAttributesV2 = Item.GetComponent <ItemAttributesV2>(); var InHandsSprites = ItemAttributesV2?.ItemSprites; SetInHand(InHandsSprites); } else { var equippedClothing = Item.GetComponent <ClothingV2>(); equippedClothing?.LinkClothingItem(this); // Some items like trash bags / mining satchels can be equipped but are not clothing and do not show on character sprite // But for the others, we call the OnClothingEquiped event. if (equippedClothing) { // call the event of equiped clothing OnClothingEquiped?.Invoke(equippedClothing, true); } } } UpdateReferenceOffset(); }
public void Refresh() { if (Dropdown.value == 0) { RelatedSpriteRenderer.Empty(); } else { var ChosenOption = Dropdown.options[Dropdown.value].text; var GotOption = thisCustomisations.PlayerCustomisations.First(x => x.Name == ChosenOption); RelatedSpriteRenderer.SetSpriteSO(GotOption.SpriteEquipped); } // set Selection and sprite RelatedSpriteRenderer.SetColor(color); SelectionColourImage.color = color; }
private void UpdateTrapVisual() { if (trapContent.GetNextFreeIndexedSlot() != null) { trapPreview.Empty(); return; } //We assume that there will be only one item on each mouse trap (for now) var slot = trapContent.GetTopOccupiedIndexedSlot(); var sprite = slot.Item.gameObject.GetComponentInChildren <SpriteHandler>(); if (sprite.GetCurrentSpriteSO() == null) { trapPreview.SetSprite(sprite.CurrentSprite); return; } trapPreview.SetSpriteSO(sprite.GetCurrentSpriteSO()); }
private bool UseChargeLogic(GameObject Performer) { if (Charges > 0) { //if this is the first charge taken off, add recharge loop if (Charges >= startCharges) { UpdateManager.Add(RegenerateCharge, rechargeTimeInSeconds); } SyncCharges(Charges, Charges - 1); if (Charges > 0) { spriteHandler.ChangeSprite(ScaleChargesToSpriteIndex()); } else { _ = SoundManager.PlayNetworkedForPlayer(recipient: Performer, OutOfChargesSFXA, sourceObj: gameObject); spriteHandler.Empty(); } return(true); } return(false); }
/// <summary> /// Uses one charge from the emag, returns true if successful /// </summary> public bool UseCharge(HandApply interaction) { if (Charges > 0) { //if this is the first charge taken off, add recharge loop if (Charges >= startCharges) { UpdateManager.Add(RegenerateCharge, rechargeTimeInSeconds); } SyncCharges(Charges, Charges - 1); if (Charges > 0) { spriteHandler.ChangeSprite(ScaleChargesToSpriteIndex()); } else { SoundManager.PlayNetworkedForPlayer(recipient: interaction.Performer, sndName: OutOfChargesSFX, sourceObj: gameObject); spriteHandler.Empty(); } return(true); } return(false); }
public static SpriteUpdateMessage.NetMessage Deserialize(this NetworkReader reader) { var message = new SpriteUpdateMessage.NetMessage(); SpriteUpdateMessage.SpriteUpdateEntry UnprocessedData = null; while (true) { UnprocessedData = null; bool ProcessSection = true; uint NetID = reader.ReadUInt32(); if (NetID == 0) { break; } if (NetworkIdentity.spawned.ContainsKey(NetID) == false || NetworkIdentity.spawned[NetID] == null) { ProcessSection = false; } string Name = reader.ReadString(); if (ProcessSection == false || NetworkIdentity.spawned.ContainsKey(NetID) == false || SpriteHandlerManager.PresentSprites.ContainsKey(NetworkIdentity.spawned[NetID]) == false || SpriteHandlerManager.PresentSprites[NetworkIdentity.spawned[NetID]].ContainsKey(Name) == false) { ProcessSection = false; } if (ProcessSection == false) { UnprocessedData = new SpriteUpdateMessage.SpriteUpdateEntry(); UnprocessedData.name = Name; UnprocessedData.id = NetID; } SpriteHandler SP = null; if (ProcessSection) { SP = SpriteHandlerManager.PresentSprites[NetworkIdentity.spawned[NetID]][Name]; } while (true) { byte Operation = reader.ReadByte(); if (Operation == 255) { if (ProcessSection == false) { SpriteUpdateMessage.UnprocessedData.Add(UnprocessedData); } break; } if (Operation == 1) { int SpriteID = reader.ReadInt32(); if (ProcessSection) { SP.SetSpriteSO(SpriteCatalogue.Instance.Catalogue[SpriteID], Network: false); } else { UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.PresentSpriteSet); UnprocessedData.arg.Add(SpriteID); } } if (Operation == 2) { int Variant = reader.ReadInt32(); if (ProcessSection) { SP.ChangeSpriteVariant(Variant, NetWork: false); } else { UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.VariantIndex); UnprocessedData.arg.Add(Variant); } } if (Operation == 3) { int Sprite = reader.ReadInt32(); if (ProcessSection) { SP.ChangeSprite(Sprite, false); } else { UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.CataloguePage); UnprocessedData.arg.Add(Sprite); } } if (Operation == 4) { int SpriteAnimate = reader.ReadInt32(); if (ProcessSection) { SP.AnimateOnce(SpriteAnimate, false); } else { UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.AnimateOnce); UnprocessedData.arg.Add(SpriteAnimate); } } if (Operation == 5) { if (ProcessSection) { SP.PushTexture(false); } else { UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.PushTexture); } } if (Operation == 6) { if (ProcessSection) { SP.Empty(false); } else { UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.Empty); } } if (Operation == 7) { if (ProcessSection) { SP.PushClear(false); } else { UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.PushClear); } } if (Operation == 8) { if (ProcessSection) { SP.ClearPallet(false); } else { UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.ClearPallet); } } if (Operation == 9) { Color TheColour = reader.ReadColor(); if (ProcessSection) { SP.SetColor(TheColour, false); } else { UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.SetColour); UnprocessedData.arg.Add(Convert.ToChar(Mathf.RoundToInt(TheColour.r * 255))); UnprocessedData.arg.Add(Convert.ToChar(Mathf.RoundToInt(TheColour.g * 255))); UnprocessedData.arg.Add(Convert.ToChar(Mathf.RoundToInt(TheColour.b * 255))); UnprocessedData.arg.Add(Convert.ToChar(Mathf.RoundToInt(TheColour.a * 255))); } } if (Operation == 10) { int paletteCount = reader.ReadByte(); List <Color> Colours = new List <Color>(); for (int i = 0; i < paletteCount; i++) { Colours.Add(reader.ReadColor()); } if (ProcessSection) { SP.SetPaletteOfCurrentSprite(Colours, false); } else { UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.Pallet); UnprocessedData.arg.Add(Convert.ToChar(paletteCount)); foreach (var color in Colours) { UnprocessedData.arg.Add(Convert.ToChar(Mathf.RoundToInt(color.r * 255))); UnprocessedData.arg.Add(Convert.ToChar(Mathf.RoundToInt(color.g * 255))); UnprocessedData.arg.Add(Convert.ToChar(Mathf.RoundToInt(color.b * 255))); UnprocessedData.arg.Add(Convert.ToChar(Mathf.RoundToInt(color.a * 255))); } } } } } return(message); }
public static SpriteUpdateMessage.NetMessage Deserialize(this NetworkReader reader) { var message = new SpriteUpdateMessage.NetMessage(); SpriteUpdateMessage.SpriteUpdateEntry UnprocessedData = null; while (true) { UnprocessedData = null; bool ProcessSection = true; uint NetID = reader.ReadUInt32(); if (NetID == 0) { break; } if (NetworkIdentity.spawned.ContainsKey(NetID) == false || NetworkIdentity.spawned[NetID] == null) { ProcessSection = false; } string Name = reader.ReadString(); if (ProcessSection == false || NetworkIdentity.spawned.ContainsKey(NetID) == false || SpriteHandlerManager.PresentSprites.ContainsKey(NetworkIdentity.spawned[NetID]) == false || SpriteHandlerManager.PresentSprites[NetworkIdentity.spawned[NetID]].ContainsKey(Name) == false) { ProcessSection = false; } if (ProcessSection == false) { UnprocessedData = new SpriteUpdateMessage.SpriteUpdateEntry(); UnprocessedData.name = Name; UnprocessedData.id = NetID; } SpriteHandler SP = null; if (ProcessSection) { SP = SpriteHandlerManager.PresentSprites[NetworkIdentity.spawned[NetID]][Name]; } while (true) { byte Operation = reader.ReadByte(); if (Operation == 255) { if (ProcessSection == false) { SpriteUpdateMessage.UnprocessedData.Add(UnprocessedData); } break; } if (Operation == 1) { int SpriteID = reader.ReadInt32(); if (ProcessSection) { try { SP.SetSpriteSO(SpriteCatalogue.Instance.Catalogue[SpriteID], networked: false); } catch (Exception e) { Logger.Log("ddD"); } } else { UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.PresentSpriteSet); UnprocessedData.arg.Add(SpriteID); } } if (Operation == 2) { int Variant = reader.ReadInt32(); if (ProcessSection) { SP.ChangeSpriteVariant(Variant, networked: false); } else { UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.VariantIndex); UnprocessedData.arg.Add(Variant); } } if (Operation == 3) { int Sprite = reader.ReadInt32(); if (ProcessSection) { SP.ChangeSprite(Sprite, false); } else { UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.CataloguePage); UnprocessedData.arg.Add(Sprite); } } if (Operation == 4) { int SpriteAnimate = reader.ReadInt32(); if (ProcessSection) { SP.AnimateOnce(SpriteAnimate, false); } else { UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.AnimateOnce); UnprocessedData.arg.Add(SpriteAnimate); } } if (Operation == 5) { if (ProcessSection) { SP.PushTexture(false); } else { UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.PushTexture); } } if (Operation == 6) { if (ProcessSection) { SP.Empty(false); } else { UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.Empty); } } if (Operation == 7) { if (ProcessSection) { SP.PushClear(false); } else { UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.PushClear); } } if (Operation == 8) { if (ProcessSection) { SP.ClearPalette(false); } else { UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.ClearPallet); } } if (Operation == 9) { Color TheColour = reader.ReadColor(); if (ProcessSection) { if (SP) { //TODO: remove this check - registering arrives after the sprite update, all clients will disconnect after a runtime //removing and readding a bodypart through surgery would cause it, since the network identity already exists unlike the creation of a new human SP.SetColor(TheColour, false); } } else { UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.SetColour); UnprocessedData.arg.Add(Convert.ToChar(Mathf.RoundToInt(TheColour.r * 255))); UnprocessedData.arg.Add(Convert.ToChar(Mathf.RoundToInt(TheColour.g * 255))); UnprocessedData.arg.Add(Convert.ToChar(Mathf.RoundToInt(TheColour.b * 255))); UnprocessedData.arg.Add(Convert.ToChar(Mathf.RoundToInt(TheColour.a * 255))); } } if (Operation == 10) { int paletteCount = reader.ReadByte(); List <Color> Colours = new List <Color>(); for (int i = 0; i < paletteCount; i++) { Colours.Add(reader.ReadColor()); } if (ProcessSection) { SP.SetPaletteOfCurrentSprite(Colours, false); } else { UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.Pallet); UnprocessedData.arg.Add(Convert.ToChar(paletteCount)); foreach (var color in Colours) { UnprocessedData.arg.Add(Convert.ToChar(Mathf.RoundToInt(color.r * 255))); UnprocessedData.arg.Add(Convert.ToChar(Mathf.RoundToInt(color.g * 255))); UnprocessedData.arg.Add(Convert.ToChar(Mathf.RoundToInt(color.b * 255))); UnprocessedData.arg.Add(Convert.ToChar(Mathf.RoundToInt(color.a * 255))); } } } } } return(message); }
public StartScanning ProcessSection(int Start, int Scanning, string SerialiseData) { bool ProcessSection = true; int InitialStart = Start; Scanning = GoToIndexOfCharacter(SerialiseData, '@', Start); uint NetID = uint.Parse(SerialiseData.Substring(Start, Scanning - Start)); if (NetworkIdentity.spawned.ContainsKey(NetID) == false || NetworkIdentity.spawned[NetID] == null) { ProcessSection = false; } Start = Scanning + 1; Scanning = GoToIndexOfCharacter(SerialiseData, '{', Scanning); string Name = SerialiseData.Substring(Start, Scanning - Start); if (ProcessSection == false || NetworkIdentity.spawned.ContainsKey(NetID) == false || SpriteHandlerManager.Instance.PresentSprites.ContainsKey(NetworkIdentity.spawned[NetID]) == false || SpriteHandlerManager.Instance.PresentSprites[NetworkIdentity.spawned[NetID]].ContainsKey(Name) == false) { ProcessSection = false; } SpriteHandler SP = null; if (ProcessSection) { SP = SpriteHandlerManager.Instance.PresentSprites[NetworkIdentity.spawned[NetID]][Name]; } Scanning++; if (SerialiseData.Length > Scanning && SerialiseData[Scanning] == '>') { Scanning += 1; Start = Scanning; Scanning = GotoIndexOfNextControlCharacter(SerialiseData, Scanning); if (ProcessSection) { int SpriteID = int.Parse(SerialiseData.Substring(Start, Scanning - Start)); SP.SetSpriteSO(SpriteCatalogue.Instance.Catalogue[SpriteID], Network: false); } } if (SerialiseData.Length > Scanning && SerialiseData[Scanning] == '<') { Scanning += 1; Start = Scanning; Scanning = GotoIndexOfNextControlCharacter(SerialiseData, Scanning); if (ProcessSection) { SP.ChangeSpriteVariant(int.Parse(SerialiseData.Substring(Start, Scanning - Start)), NetWork: false); } } if (SerialiseData.Length > Scanning && SerialiseData[Scanning] == '&') { Scanning += 1; Start = Scanning; Scanning = GotoIndexOfNextControlCharacter(SerialiseData, Scanning); if (ProcessSection) { SP.ChangeSprite(int.Parse(SerialiseData.Substring(Start, Scanning - Start)), false); } } if (SerialiseData.Length > Scanning && SerialiseData[Scanning] == '#') { Scanning += 1; Start = Scanning; Scanning = GotoIndexOfNextControlCharacter(SerialiseData, Scanning); if (ProcessSection) { SP.AnimateOnce(int.Parse(SerialiseData.Substring(Start, Scanning - Start)), false); } } if (SerialiseData.Length > Scanning && SerialiseData[Scanning] == ',') { Scanning++; if (ProcessSection) { SP.PushTexture(false); } } if (SerialiseData.Length > Scanning && SerialiseData[Scanning] == '?') { Scanning++; if (ProcessSection) { SP.Empty(false); } } if (SerialiseData.Length > Scanning && SerialiseData[Scanning] == '~') { Scanning++; if (ProcessSection) { SP.PushClear(false); } } if (SerialiseData.Length > Scanning && SerialiseData[Scanning] == '^') { Scanning++; if (ProcessSection) { SP.ClearPallet(false); } } if (SerialiseData.Length > Scanning && SerialiseData[Scanning] == '`') { Color TheColour = Color.white; TheColour.r = ((int)SerialiseData[Scanning + 1] / 255f); TheColour.g = ((int)SerialiseData[Scanning + 2] / 255f); TheColour.b = ((int)SerialiseData[Scanning + 3] / 255f); TheColour.a = ((int)SerialiseData[Scanning + 4] / 255f); Scanning = Scanning + 4; if (ProcessSection) { SP.SetColor(TheColour, false); } Scanning++; } if (SerialiseData.Length > Scanning && SerialiseData[Scanning] == '%') { Scanning = Scanning + 1; int paletteCount = SerialiseData[Scanning]; List <Color> Colours = new List <Color>(); for (int i = 0; i < paletteCount; i++) { Colours.Add(GetColourFromStringIndex(SerialiseData, Scanning + (i * 4))); } Scanning = Scanning + 1; Scanning = Scanning + 4 * paletteCount; if (ProcessSection) { SP.SetPaletteOfCurrentSprite(Colours, false); } } Scanning++; Start = Scanning; if (ProcessSection == false) { UnprocessedData.Add(SerialiseData.Substring(InitialStart, Start - InitialStart)); } StartScanning StartScanning = new StartScanning() { INStart = Start, INScanning = Scanning, }; return(StartScanning); }