public static Result <ItemUsedResult> UseItem(INetworkItemInstance item, Character character, ItemContext useContext) { var net = character.GetComponent <NetworkIdentity>(); var bridge = character.GetComponent <UNetActionsBridge>(); if (net != null && bridge != null) { if (net.isClient) { _logger.LogVerbose($"[Client] Trying to use item with guid {item.ID}"); bridge.Cmd_RequestUseItem(new RequestUseItemMessage() { itemGuid = item.ID, useAmount = (ushort)useContext.useAmount, targetIndex = (short)useContext.targetIndex }); return(new Result <ItemUsedResult>(new ItemUsedResult(useContext.useAmount, false, 0f))); // TODO: Set cooldown time. } } _logger.Warning($"UseItem() couldn't find {nameof(NetworkIdentity)} or {nameof(UNetActionsBridge)} on player object;", item); return(new Result <ItemUsedResult>(null, Errors.NetworkNoAuthority)); }
public static Result <GameObject> DropItem(INetworkItemInstance item, Character character, Vector3 worldPosition) { var bridge = character.GetComponent <PUN2ActionsBridge>(); if (bridge != null && bridge.photonView != null) { if (bridge.photonView.IsMine /*!bridge.photonView.IsServer() /*net.isClient*/) { bridge.photonView.RPC(nameof(bridge.Cmd_RequestDropItem), PhotonNetwork.MasterClient, /*itemGuid: */ item.ID.ToByteArray(), /*worldPosition: */ worldPosition ); return(new Result <GameObject>(null)); } } _logger.Warning($"DropItem() couldn't find {nameof(PhotonView)} or {nameof(PUN2ActionsBridge)} on player object;", item); return(new Result <GameObject>(null, Errors.NetworkNoAuthority)); }
public static Result <GameObject> DropItem(INetworkItemInstance item, Character character, Vector3 worldPosition) { var net = character.GetComponent <NetworkIdentity>(); var bridge = character.GetComponent <UNetActionsBridge>(); if (net != null && bridge != null) { if (net.isClient) { bridge.Cmd_RequestDropItem(new RequestDropItemMessage() { itemGuid = item.ID, worldPosition = worldPosition, }); return(new Result <GameObject>(null)); } } _logger.Warning($"DropItem() couldn't find {nameof(NetworkIdentity)} or {nameof(UNetActionsBridge)} on player object;", item); return(new Result <GameObject>(null, Errors.NetworkNoAuthority)); }
public static Result <ItemUsedResult> UseItem(INetworkItemInstance item, Character character, ItemContext useContext) { var bridge = character.GetComponent <PUN2ActionsBridge>(); if (bridge != null && bridge.photonView != null) { if (bridge.photonView.IsMine /*!bridge.photonView.IsServer() /*net.isClient*/) { _logger.LogVerbose($"[Client] Trying to use item with guid {item.ID}"); bridge.photonView.RPC(nameof(bridge.Cmd_RequestUseItem), PhotonNetwork.MasterClient, /*itemGuid: */ item.ID.ToByteArray(), /*useAmount: */ useContext.useAmount, /*targetIndex: */ useContext.targetIndex ); return(new Result <ItemUsedResult>(new ItemUsedResult(useContext.useAmount, false, 0f))); // TODO: Set cooldown time. } } _logger.Warning($"UseItem() couldn't find {nameof(PhotonView)} or {nameof(PUN2ActionsBridge)} on player object;", item); return(new Result <ItemUsedResult>(null, Errors.NetworkNoAuthority)); }
public Result <bool> ValidateDropItem(PhotonView identity, Guid itemGuid, Player player, out INetworkItemInstance outItem, ref Vector3 worldPosition) { outItem = null; if (CheckGuidBytes(itemGuid.ToByteArray()) == false) { return(Failed()); } if (CheckItemPermission(identity, itemGuid, ReadWritePermission.ReadWrite, out outItem) == false) { return(Failed()); } if (Vector3.Distance(worldPosition, player.transform.position) > player.GetComponent <IDropHandler>().maxDropDistance) { logger.LogVerbose("[Server] player suggested position for drop is too far away from player; Forcing drop position", this); worldPosition = player.transform.position + (player.transform.forward * 3f); // TODO: Use drop handler. } return(true); }
public Result <bool> ValidateUseItem(PhotonView identity, Guid itemGuid, ushort useAmount, out INetworkItemInstance outItem) { outItem = null; if (CheckGuidBytes(itemGuid.ToByteArray()) == false) { return(Failed()); } if (CheckItemPermission(identity, itemGuid, ReadWritePermission.ReadWrite, out outItem) == false) { return(Failed()); } // TODO: Consider creating a distance check to Use items directly from the world, rather than from a collection (requires permission changes on items). if (outItem.collectionEntry.amount < useAmount) { return(Failed()); } return(true); }
private bool CheckItemPermission(PhotonView identity, System.Guid itemGuid, ReadWritePermission minimalPermission, out INetworkItemInstance outItem) { outItem = ServerItemRegistry.Get(itemGuid) as INetworkItemInstance; if (outItem?.collectionEntry?.collection == null) { return(false); } if (CheckCollectionPermission(identity, outItem.collectionEntry.collection, minimalPermission) == false) { return(false); } return(true); }
public Result <bool> ValidateSellItemToVendor(PhotonView identity, byte[] vendorGuidBytes, Guid vendorGuid, byte[] itemGuidBytes, Guid itemGuid, ushort amount, out INetworkVendor <IItemInstance> outVendor, out INetworkItemInstance outItem) { outVendor = null; outItem = null; if (CheckGuidBytes(vendorGuidBytes) == false || CheckGuidBytes(itemGuidBytes) == false) { return(Failed()); } outItem = ServerItemRegistry.Get(itemGuid) as INetworkItemInstance; outVendor = ServerVendorRegistry.itemVendors.Get(vendorGuid); if (outItem == null || outVendor == null) { return(Failed()); } // Item has to be in a collection to be sellable. if (outItem.collectionEntry?.collection == null) { return(Failed()); } if (outItem.collectionEntry.amount < amount) { return(Failed()); } return(true); }
public Result <bool> ValidateBuyItemFromVendor(PhotonView identity, byte[] vendorGuidBytes, Guid vendorGuid, byte[] itemGuidBytes, Guid itemGuid, ushort amount, out INetworkVendor <IItemInstance> outVendor, out INetworkItemInstance outItem) { outVendor = null; outItem = null; if (CheckGuidBytes(vendorGuidBytes) == false || CheckGuidBytes(itemGuidBytes) == false) { return(Failed()); } outItem = ServerItemRegistry.Get(itemGuid) as INetworkItemInstance; outVendor = ServerVendorRegistry.itemVendors.Get(vendorGuid); if (outItem == null || outVendor == null) { return(Failed()); } var tempItem = outItem; var vendorItemAmount = outVendor.itemCollection.GetAmount(o => o?.ID == tempItem.ID); if (vendorItemAmount < amount) { return(Failed()); } // Check if player has read permission to vendor collection if (CheckClientVendorPermission(identity, outVendor, outItem) == false) { return(Failed()); } return(true); }
public Result <bool> ValidateSellItemToVendor(NetworkIdentity identity, RequestSellItemToVendorMessage data, out INetworkVendor <IItemInstance> outVendor, out INetworkItemInstance outItem) { outVendor = null; outItem = null; if (CheckGuidBytes(data.vendorGuid.bytes) == false || CheckGuidBytes(data.itemGuid.bytes) == false) { return(Failed()); } outItem = ServerItemRegistry.Get(data.itemGuid) as INetworkItemInstance; outVendor = ServerVendorRegistry.itemVendors.Get(data.vendorGuid); if (outItem == null || outVendor == null) { return(Failed()); } // Item has to be in a collection to be sellable. if (outItem.collectionEntry?.collection == null) { return(Failed()); } if (outItem.collectionEntry.amount < data.amount) { return(Failed()); } return(true); }
public Result <bool> ValidateBuyItemFromVendor(NetworkIdentity identity, RequestBuyItemFromVendorMessage data, out INetworkVendor <IItemInstance> outVendor, out INetworkItemInstance outItem) { outVendor = null; outItem = null; if (CheckGuidBytes(data.vendorGuid.bytes) == false || CheckGuidBytes(data.itemGuid.bytes) == false) { return(Failed()); } outItem = ServerItemRegistry.Get(data.itemGuid) as INetworkItemInstance; outVendor = ServerVendorRegistry.itemVendors.Get(data.vendorGuid); if (outItem == null || outVendor == null) { return(Failed()); } var tempItem = outItem; var vendorItemAmount = outVendor.itemCollection.GetAmount(o => o?.ID == tempItem.ID); if (vendorItemAmount < data.amount) { return(Failed()); } // Check if player has read permission to vendor collection if (CheckClientVendorPermission(identity, outVendor, outItem) == false) { return(Failed()); } return(true); }
public Result <bool> ValidateUseItem(NetworkIdentity identity, RequestUseItemMessage data, out INetworkItemInstance outItem) { outItem = null; if (CheckGuidBytes(data.itemGuid.bytes) == false) { return(Failed()); } if (CheckItemPermission(identity, data.itemGuid, ReadWritePermission.ReadWrite, out outItem) == false) { return(Failed()); } // TODO: Consider creating a distance check to Use items directly from the world, rather than from a collection (requires permission changes on items). if (outItem.collectionEntry.amount < data.useAmount) { return(Failed()); } return(true); }