Advertisement
Mitoss1

MyEquippableCharacter - UNetEquippableCharacter

May 23rd, 2019
480
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.97 KB | None | 0 0
  1. using Devdog.Rucksack;
  2. using Devdog.Rucksack.CharacterEquipment;
  3. using Devdog.Rucksack.UI;
  4. using Devdog.Rucksack.Characters;
  5. using Devdog.Rucksack.CharacterEquipment.Items;
  6. using Devdog.Rucksack.Collections;
  7. using UnityEngine;
  8. using System.Collections.Generic;
  9. using System;
  10. using System.Collections;
  11. using Devdog.Rucksack.Items;
  12. using UnityEngine.Networking;
  13. using Devdog.Rucksack.Database;
  14. using static Devdog.Rucksack.Collections.ICollection;
  15.  
  16.  
  17. public class MyEquipableCharacter : UNetEquippableCharacter
  18. {
  19. public UNetInventoryPlayer invPlayer;
  20.  
  21. public UNetEquipmentCollectionCreator equipmentInv;
  22.  
  23. public UNetItemCollectionCreator weaponsInv;
  24. public UNetItemCollectionCreator defenseInv;
  25. public UNetItemCollectionCreator shipInv;
  26. public UNetItemCollectionCreator heroesInv;
  27.  
  28. [SerializeField] public UnityItemDefinitionDatabase _myDataBase;
  29.  
  30. public void SetSlot(ushort index, ushort amount)
  31. {
  32. foreach (var conn in NetworkServer.connections)
  33. {
  34. if (conn != null)
  35. {
  36. if (IsValidConnection(conn))
  37. {
  38. bridge.TargetRpc_SetSlot(conn, new SlotDataMessage()
  39. {
  40. collectionGuid = equipmentInv.collection.ID,
  41. itemInstanceGuid = System.Guid.Empty,
  42. index = index,
  43. amount = amount
  44. });
  45. }
  46. }
  47. }
  48. }
  49.  
  50. public override Result<EquipmentResult<IEquippableItemInstance>[]> Equip(IEquippableItemInstance item, int amount = 1)
  51. {
  52. var equipped = base.Equip(item, amount);
  53. if (equipped.error != null)
  54. {
  55. Debug.Log("Error: " + equipped.error);
  56. }
  57.  
  58. return equipped;
  59. }
  60.  
  61. public override Result<EquipmentResult<IEquippableItemInstance>> EquipAt(int index, IEquippableItemInstance item, int amount = 1)
  62. {
  63. var equipped = base.EquipAt(index, item, amount);
  64. if (equipped.error != null)
  65. {
  66. Debug.Log("Error: " + equipped.error);
  67. }
  68.  
  69. return equipped;
  70. }
  71.  
  72. public override Result<UnEquipmentResult> UnEquip(IEquippableItemInstance item, int amount = 1)
  73. {
  74. Debug.Log("Unequip Method");
  75.  
  76. var collection = equipmentInv.collection;
  77. var index = collection.IndexOf(item);
  78.  
  79. var unEquipped = base.UnEquip(item, amount);
  80. if(unEquipped.error == null)
  81. {
  82. SendTargetRpc_NotifyItemUnEquipped(unEquipped.result.mountPoint);
  83.  
  84. SetSlot((ushort)index, (ushort)amount);
  85. collection.Set(index, null, 0);
  86.  
  87. string collectionName = item.itemDefinition.collectionName;
  88.  
  89. if (collectionName == weaponsInv.collectionName)
  90. {
  91. Debug.Log("Weapons UI Collection: " + weaponsInv.collection);
  92.  
  93. var col = weaponsInv.collection as Devdog.Rucksack.Collections.ICollection<IItemInstance>;
  94.  
  95. col.Add(item);
  96. }
  97.  
  98. else if (collectionName == defenseInv.collectionName)
  99. {
  100. Debug.Log("Defense UI Collection: " + defenseInv.collection);
  101.  
  102. var col = defenseInv.collection as Devdog.Rucksack.Collections.ICollection<IItemInstance>;
  103.  
  104. col.Add(item);
  105. }
  106.  
  107. return unEquipped;
  108. }
  109.  
  110. else
  111. {
  112. Debug.Log("Error: " + unEquipped.error);
  113.  
  114. return new Result<UnEquipmentResult>(new UnEquipmentResult()
  115. {
  116. });
  117. }
  118. }
  119.  
  120. public override Result<UnEquipmentResult> UnEquipAt(int index, int amount = 1)
  121. {
  122. Debug.Log("UnequipAt Method");
  123.  
  124. var collection = equipmentInv.collection;
  125. var item = collection[index];
  126.  
  127. var unEquipped = base.UnEquipAt(index, amount);
  128. if (unEquipped.error == null)
  129. {
  130. SendTargetRpc_NotifyItemUnEquipped(unEquipped.result.mountPoint);
  131.  
  132. string collectionName = item.itemDefinition.collectionName;
  133.  
  134. if (collectionName == weaponsInv.collectionName)
  135. {
  136. Debug.Log("Weapons UI Collection: " + weaponsInv.collection);
  137.  
  138. var col = weaponsInv.collection as Devdog.Rucksack.Collections.ICollection<IItemInstance>;
  139.  
  140. col.Add(item);
  141. }
  142.  
  143. else if (collectionName == defenseInv.collectionName)
  144. {
  145. Debug.Log("Defense UI Collection: " + defenseInv.collection);
  146.  
  147. var col = defenseInv.collection as Devdog.Rucksack.Collections.ICollection<IItemInstance>;
  148.  
  149. col.Add(item);
  150. }
  151.  
  152. return unEquipped;
  153. }
  154.  
  155. else
  156. {
  157. Debug.Log("Error: " + unEquipped.error);
  158.  
  159. return new Result<UnEquipmentResult>(new UnEquipmentResult()
  160. {
  161. });
  162. }
  163. }
  164.  
  165. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement