public void ValidateInvInteraction(string slot, GameObject gObj) { if (!_inventory[slot] && _inventory.ContainsValue(gObj)) { UpdateSlotMessage.Send(gameObject, slot, gObj); SetInventorySlot(slot, gObj); //Clean up other slots HashSet <string> toBeCleared = new HashSet <string>(); foreach (string key in _inventory.Keys) { if (key.Equals(slot) || !_inventory[key]) { continue; } if (_inventory[key].Equals(gObj)) { toBeCleared.Add(key); } } ClearInventorySlot(toBeCleared.ToArray()); // Debug.LogFormat("Approved moving {0} to slot {1}", gObj, slot); } else { Debug.LogWarningFormat("Unable to validateInvInteraction {0}:{1}", slot, gObj.name); } }
public void CmdEatFood(GameObject food, string fromSlot) { if (Inventory[fromSlot] == null) { //Already been eaten or the food is no longer in hand return; } FoodBehaviour baseFood = food.GetComponent <FoodBehaviour>(); soundNetworkActions.CmdPlaySoundAtPlayerPos("EatFood"); PlayerHealth playerHealth = GetComponent <PlayerHealth>(); //FIXME: remove health and blood changes after TDM //and use this Cmd for healing hunger and applying //food related attributes instead: playerHealth.AddHealth(baseFood.healAmount); playerHealth.BloodLevel += baseFood.healAmount; playerHealth.StopBleeding(); PoolManager.Instance.PoolNetworkDestroy(food); UpdateSlotMessage.Send(gameObject, fromSlot, null, true); Inventory[fromSlot] = null; equipment.ClearItemSprite(fromSlot); }
/// <summary> /// Sets the item to the slot and sends network messages to update character sprites and the player's UI /// </summary> public static void EquipInInvSlot(InventorySlot inventorySlot, GameObject item) { if (inventorySlot.IsUISlot) { UpdateSlotMessage.Send(inventorySlot.Owner, item, false, inventorySlot.equipSlot); if (IsEquipSpriteSlot(inventorySlot.equipSlot)) { var att = item.GetComponent <ItemAttributes>(); var reference = att.clothingReference; { if (inventorySlot.equipSlot == EquipSlot.leftHand) { reference = att.NetworkInHandRefLeft(); } else if (inventorySlot.equipSlot == EquipSlot.rightHand) { reference = att.NetworkInHandRefRight(); } } if (att.spriteType == SpriteType.Clothing || att.hierarchy.Contains("headset") || att.hierarchy.Contains("storage/backpack") || att.hierarchy.Contains("storage/bag") || att.hierarchy.Contains("storage/belt") || att.hierarchy.Contains("tank") || inventorySlot.equipSlot == EquipSlot.handcuffs || inventorySlot.equipSlot == EquipSlot.leftHand || inventorySlot.equipSlot == EquipSlot.rightHand) { EquipmentSpritesMessage.SendToAll(inventorySlot.Owner, (int)inventorySlot.equipSlot, reference); } } } inventorySlot.Item = item; }
public void DropItem(string slot, Vector3 dropWorldPos, bool forceClientInform = true) { EquipmentPool.DropGameObjectAtPos(gameObject, Inventory[slot], dropWorldPos); Inventory[slot] = null; equipment.ClearItemSprite(slot); UpdateSlotMessage.Send(gameObject, slot, null, forceClientInform); }
public void UpdateInventorySlots(GameObject recipient) { for (int i = 0; i < slotNames.Length; i++) { InventorySlot invSlot = Inventory[slotNames[i]]; UpdateSlotMessage.Send(recipient, invSlot.UUID, null, invSlot.Item); } }
public void UpdateInventorySlots() { foreach (KeyValuePair <EquipSlot, InventorySlot> slot in Inventory) { if (slot.Value.Item != null) { UpdateSlotMessage.Send(gameObject, slot.Value.Item, false, slot.Key); } } }
public void UpdateInventorySlots() { for (int i = 0; i < playerSlots.Length; i++) { InventorySlot inventorySlot = Inventory[playerSlots[i]]; if (inventorySlot.Item != null) { UpdateSlotMessage.Send(inventorySlot.Owner, inventorySlot.Item, false, inventorySlot.equipSlot); } } }
public static UpdateSlotMessage Send(GameObject recipient, GameObject item, bool removeItem, EquipSlot sentEquipSlot = 0) { UpdateSlotMessage msg = new UpdateSlotMessage { Recipient = recipient.GetComponent<NetworkIdentity>().netId, Item = item.GetComponent<NetworkIdentity>().netId, RemoveItem = removeItem, equipSlot = sentEquipSlot }; msg.SendTo(recipient); return msg; }
/// <summary> /// Sets the item to the slot and sends network messages to update character sprites and the player's UI /// </summary> public static void EquipInInvSlot(InventorySlot inventorySlot, GameObject item, bool isInit = false) { if (inventorySlot.IsUISlot) { UpdateSlotMessage.Send(inventorySlot.Owner, item, false, inventorySlot.equipSlot); if (IsEquipSpriteSlot(inventorySlot.equipSlot)) { EquipmentSpritesMessage.SendToAll(inventorySlot.Owner, (int)inventorySlot.equipSlot, item, isInit); } } inventorySlot.Item = item; }
/// <summary> /// Clears the slot and sends network messages to update character sprites and the player's UI /// </summary> public static void ClearInvSlot(InventorySlot inventorySlot) { if (inventorySlot.IsUISlot) { UpdateSlotMessage.Send(inventorySlot.Owner, inventorySlot.Item, true, inventorySlot.equipSlot); if (IsEquipSpriteSlot(inventorySlot.equipSlot)) { EquipmentSpritesMessage.SendToAll(inventorySlot.Owner, (int)inventorySlot.equipSlot, null); } } inventorySlot.Item = null; }
/// <param name="recipient">Client GO</param> /// <param name="slot"></param> /// <param name="objectForSlot">Pass null to clear slot</param> /// <param name="forced"> /// Used for client simulation, use false if client's slot is already updated by prediction /// (to avoid updating it twice) /// </param> /// <returns></returns> public static UpdateSlotMessage Send(GameObject recipient, string slot, GameObject objectForSlot = null, bool forced = true) { UpdateSlotMessage msg = new UpdateSlotMessage { Recipient = recipient.GetComponent <NetworkIdentity>().netId, //? Slot = slot, ObjectForSlot = objectForSlot != null?objectForSlot.GetComponent <NetworkIdentity>().netId : NetworkInstanceId.Invalid, ForceRefresh = forced }; msg.SendTo(recipient); return(msg); }
public bool AddItem(GameObject itemObject, string slotName = null, bool replaceIfOccupied = false, bool forceInform = true) { string eventName = slotName ?? UIManager.Hands.CurrentSlot.eventName; if (Inventory[eventName] != null && Inventory[eventName] != itemObject && !replaceIfOccupied) { Debug.LogFormat("{0}: Didn't replace existing {1} item {2} with {3}", gameObject.name, eventName, Inventory[eventName].name, itemObject.name); return(false); } EquipmentPool.AddGameObject(gameObject, itemObject); SetInventorySlot(slotName, itemObject); UpdateSlotMessage.Send(gameObject, eventName, itemObject, forceInform); return(true); }
public bool ValidateDropItem(string slot, bool forceClientInform /* = false*/) { //decline if not dropped from hands? if (_inventory.ContainsKey(slot) && _inventory[slot]) { EquipmentPool.DropGameObject(gameObject, _inventory[slot]); // RpcAdjustItemParent(_inventory[slot], null); _inventory[slot] = null; equipment.ClearItemSprite(slot); UpdateSlotMessage.Send(gameObject, slot, null, forceClientInform); return(true); } Debug.Log("Object not found in Inventory for: " + gameObject.name); return(false); }
private void ClearInventorySlot(bool forceClientInform, params string[] slotNames) { for (int i = 0; i < slotNames.Length; i++) { Inventory[slotNames[i]] = null; if (slotNames[i] == "id" || slotNames[i] == "storage01" || slotNames[i] == "storage02" || slotNames[i] == "suitStorage") { //Not clearing onPlayer sprites for these as they don't have any } else { equipment.ClearItemSprite(slotNames[i]); } UpdateSlotMessage.Send(gameObject, slotNames[i], null, forceClientInform); } // Debug.LogFormat("Cleared {0}", slotNames); }
public static void UpdateInvSlot(bool isServer, string UUID, GameObject item, string FromUUID = "") { bool uiSlotChanged = false; string toSlotName = ""; GameObject owner = null; var index = InventorySlotList(isServer).FindIndex( x => x.UUID == UUID); if (index != -1) { var invSlot = InventorySlotList(isServer)[index]; invSlot.Item = item; if (invSlot.IsUISlot) { uiSlotChanged = true; toSlotName = invSlot.SlotName; owner = invSlot.Owner.gameObject; } } if (!string.IsNullOrEmpty(FromUUID)) { index = InventorySlotList(isServer).FindIndex( x => x.UUID == FromUUID); if (index != -1) { var invSlot = InventorySlotList(isServer)[index]; invSlot.Item = null; if (invSlot.IsUISlot) { uiSlotChanged = true; owner = invSlot.Owner.gameObject; } } } //Only ever sync UI slots straight away, storage slots will sync when they are being observed (picked up and inspected) if (isServer && uiSlotChanged) { UpdateSlotMessage.Send(owner, UUID, FromUUID, item); } if (!isServer && uiSlotChanged) { UIManager.UpdateSlot(new UISlotObject(UUID, item, FromUUID)); } }
public bool ValidateInvInteraction(string slot, GameObject gObj = null, bool forceClientInform = true) { if (!_inventory[slot] && gObj && _inventory.ContainsValue(gObj)) { UpdateSlotMessage.Send(gameObject, slot, gObj, forceClientInform); SetInventorySlot(slot, gObj); //Clean up other slots ClearObjectIfNotInSlot(gObj, slot, forceClientInform); //Debug.LogFormat("Approved moving {0} to slot {1}", gObj, slot); return(true); } if (!gObj) { return(ValidateDropItem(slot, forceClientInform)); } Debug.LogWarningFormat("Unable to validateInvInteraction {0}:{1}", slot, gObj.name); return(false); }
public void RollbackPrediction(string slotUUID, string fromSlotUUID, GameObject item) { var toSlotRequest = InventoryManager.GetSlotFromUUID(slotUUID, isServer); var slotItCameFrom = InventoryManager.GetSlotFromUUID(fromSlotUUID, isServer); if (toSlotRequest != null) { if (toSlotRequest.Item == item) //it already travelled to slot on the server, send it back for everyone { if (!ValidateInvInteraction(fromSlotUUID, slotUUID, item, true)) { Logger.LogError("Rollback failed!", Category.Inventory); } return; } } UpdateSlotMessage.Send(gameObject, fromSlotUUID, slotUUID, item, true); }
public void DropItem(string slot = "", bool forceClientInform = true) { //Drop random item if (slot == "") { slot = "uniform"; foreach (var key in Inventory.Keys) { if (Inventory[key]) { slot = key; break; } } } EquipmentPool.DropGameObject(gameObject, Inventory[slot]); Inventory[slot] = null; equipment.ClearItemSprite(slot); UpdateSlotMessage.Send(gameObject, slot, null, forceClientInform); }
public bool ValidateInvInteraction(string slot, GameObject gObj = null, bool forceClientInform = true) { //security todo: serverside check for item size UI_ItemSlot.CheckItemFit() if (!Inventory[slot] && gObj && Inventory.ContainsValue(gObj)) { UpdateSlotMessage.Send(gameObject, slot, gObj, forceClientInform); SetInventorySlot(slot, gObj); //Clean up other slots ClearObjectIfNotInSlot(gObj, slot, forceClientInform); Logger.LogTraceFormat("Approved moving {0} to slot {1}", Category.Inventory, gObj, slot); return(true); } if (!gObj) { return(ValidateDropItem(slot, forceClientInform)); } Logger.LogWarning($"Unable to validateInvInteraction {slot}:{gObj.name}", Category.Inventory); return(false); }
public void RollbackPrediction(string slot) { UpdateSlotMessage.Send(gameObject, slot, _inventory[slot], true); }
/// <summary> /// Updates the inventory slot list, transferring an item out of / into an inventory slot (or ground). /// </summary> /// <param name="isServer">whether to update this client's inventory slots or the server's inventory slots</param> /// <param name="UUID">UUID of the destination inventory slot, empty string if item is not going into an inventory slot (such as when dropping it)</param> /// <param name="item">gameobject representing the item being transferred</param> /// <param name="FromUUID">UUID of the previous inventory slot that item is coming from, empty string if it's not coming from /// another inventory slot</param> public static void UpdateInvSlot(bool isServer, string UUID, GameObject item, string FromUUID = "") { bool uiSlotChanged = false; string toSlotName = ""; GameObject fromOwner = null; GameObject toOwner = null; //find the inventory slot with the given UUID var index = InventorySlotList(isServer).FindIndex( x => x.UUID == UUID); if (index != -1) { var invSlot = InventorySlotList(isServer)[index]; //put the item in the slot invSlot.Item = item; if (invSlot.IsUISlot) { //if this is a UI slot, mark that it has been changed and keep track of the new owner so we can send the update //message uiSlotChanged = true; toSlotName = invSlot.SlotName; toOwner = invSlot.Owner.gameObject; } } if (!string.IsNullOrEmpty(FromUUID)) { //if this came from another slot, find it index = InventorySlotList(isServer).FindIndex( x => x.UUID == FromUUID); if (index != -1) { var invSlot = InventorySlotList(isServer)[index]; //remove the item from the previous slot invSlot.Item = null; if (invSlot.IsUISlot) { //if the previous slot had an owner, track the owner so we can include it in the update message uiSlotChanged = true; fromOwner = invSlot.Owner.gameObject; } } } //Only ever sync UI slots straight away, storage slots will sync when they are being observed (picked up and inspected) if (isServer && uiSlotChanged) { //send the update to the player who the item was taken from and the player it was //given to if (fromOwner != null) { UpdateSlotMessage.Send(fromOwner, UUID, FromUUID, item); } if (toOwner != null) { UpdateSlotMessage.Send(toOwner, UUID, FromUUID, item); } } if (!isServer && uiSlotChanged) { UIManager.UpdateSlot(new UISlotObject(UUID, item, FromUUID)); } }