Advertisement
tcyknhrabirwjyljhp

Untitled

Sep 6th, 2022
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.71 KB | None | 0 0
  1. if (args.Length == 0)
  2. {
  3. return HelpCommand.Execute(new string[]
  4. {
  5. GiveCommand.usage
  6. });
  7. }
  8. PlayerEntity player = GameManager.Player;
  9. if (!player)
  10. {
  11. return "No active player found.";
  12. }
  13. string result = string.Empty;
  14. string text = args[0].ToLower();
  15. bool flag = false;
  16. bool flag2 = false;
  17. int num = 1;
  18. int loadedQuantity = 0;
  19. int num2 = 0;
  20. bool flag3 = false;
  21. EntityConfig[] array = null;
  22. EntityConfig entityConfig = null;
  23. EntityBehaviour entityBehaviour = null;
  24. InventoryItemConfig inventoryItemConfig = null;
  25. EntityTypes entityTypes = EntityTypes.None;
  26. player.Equipment.AddLuggageCase();
  27. if (player.Equipment.AddLoadout(text, GiveCommand.comparer))
  28. {
  29. return "Player has recieved loadout '" + text + "'.";
  30. }
  31. if (EntityManager.IsEntityTypePlural(text, out entityTypes))
  32. {
  33. if (EntityManager.TryGetAllEntityType(entityTypes, out array) > 0)
  34. {
  35. flag2 = true;
  36. }
  37. }
  38. else if (EntityManager.TryFindEntityType(text, out entityConfig) && entityConfig != null)
  39. {
  40. array = new EntityConfig[]
  41. {
  42. entityConfig
  43. };
  44. entityTypes = entityConfig.EntityType;
  45. flag2 = true;
  46. }
  47. if (flag2)
  48. {
  49. if (args.Length > 1 && int.TryParse(args[1], out num))
  50. {
  51. num = Mathf.Max(num, 1);
  52. flag3 = true;
  53. }
  54. if (EntityManager.TryFindEntityType(text, out entityConfig))
  55. {
  56. array = new EntityConfig[]
  57. {
  58. entityConfig
  59. };
  60. }
  61. if (array.Length != 0)
  62. {
  63. int num3 = num;
  64. int num4 = 0;
  65. foreach (EntityConfig entityConfig2 in array)
  66. {
  67. int num5 = num;
  68. while (num5 > 0 && num2 < 100)
  69. {
  70. if (entityTypes == EntityTypes.Weapons)
  71. {
  72. WeaponConfig weaponConfig = entityConfig2 as WeaponConfig;
  73. if (weaponConfig != null)
  74. {
  75. WeaponAmmoTypeConfig weaponAmmoTypeConfig;
  76. if (weaponConfig.TryGetDefaultAmmoType(out weaponAmmoTypeConfig))
  77. {
  78. inventoryItemConfig = weaponAmmoTypeConfig.ItemType;
  79. loadedQuantity = weaponConfig.AmmoCapacityMax;
  80. }
  81. if (weaponConfig.ItemType)
  82. {
  83. entityBehaviour = weaponConfig.ItemType.CreateEntity(player.position, player.rotation, player.Transform);
  84. }
  85. else
  86. {
  87. entityBehaviour = entityConfig2.CreateEntity(player.position, player.rotation, player.Transform);
  88. }
  89. }
  90. }
  91. else
  92. {
  93. entityBehaviour = entityConfig2.CreateEntity(player.position, player.rotation, player.Transform);
  94. }
  95. if (entityBehaviour)
  96. {
  97. switch (entityBehaviour.EntityType)
  98. {
  99. case EntityTypes.Items:
  100. {
  101. InventoryItem itemLink;
  102. if (entityBehaviour.TryGetComponent<InventoryItem>(out itemLink))
  103. {
  104. if (flag3)
  105. {
  106. num3 = Mathf.Min(num5, itemLink.StackCountMax);
  107. }
  108. else
  109. {
  110. num3 = 1;
  111. }
  112. num3 = Mathf.Max(num3, 1);
  113. itemLink.SetQuantity(num3);
  114. if (inventoryItemConfig)
  115. {
  116. itemLink.SetLoadedType(inventoryItemConfig);
  117. itemLink.SetLoadedQuantity(loadedQuantity);
  118. }
  119. if (player.Equipment.AddItem(itemLink) != ItemTransferResult.None)
  120. {
  121. flag = true;
  122. }
  123. else if (itemLink.Config.Pickup)
  124. {
  125. Vector3 position = player.mainCameraTr.position;
  126. Vector3 vector = player.Interact.GetWorldPoint(1f);
  127. vector += new Vector3(0f, 1f * (float)num4, 0f);
  128. Quaternion.LookRotation(position - vector, Vector3.up);
  129. ItemPickup itemPickup = itemLink.ConvertToPickup();
  130. GiveCommand.DropPickup(player, itemPickup, num4);
  131. num4++;
  132. flag = true;
  133. }
  134. else
  135. {
  136. Object.Destroy(entityBehaviour.gameObject);
  137. result = "Could not add '" + text + "' to inventory or drop item as pickup.";
  138. }
  139. }
  140. break;
  141. }
  142. case EntityTypes.Weapons:
  143. {
  144. PlayerWeapon weapon;
  145. if (entityBehaviour.TryGetComponent<PlayerWeapon>(out weapon) && player.Equipment.AddWeapon(weapon) != ItemTransferResult.None)
  146. {
  147. flag = true;
  148. }
  149. break;
  150. }
  151. case EntityTypes.Pickups:
  152. {
  153. ItemPickup itemPickup;
  154. if (entityBehaviour.TryGetComponent<ItemPickup>(out itemPickup))
  155. {
  156. InventoryItem itemLink = itemPickup.ItemLink;
  157. ItemTransferResult itemTransferResult = player.Equipment.AddItem(itemLink);
  158. if (itemTransferResult > ItemTransferResult.Partial)
  159. {
  160. if (itemTransferResult == ItemTransferResult.Complete)
  161. {
  162. itemPickup.gameObject.SetActive(false);
  163. }
  164. }
  165. else
  166. {
  167. GiveCommand.DropPickup(player, itemPickup, num4);
  168. num4++;
  169. }
  170. num3 = Mathf.Max(itemLink.Quantity, 1);
  171. flag = true;
  172. }
  173. break;
  174. }
  175. default:
  176. num5 = 0;
  177. break;
  178. }
  179. }
  180. num5 -= num3;
  181. num2++;
  182. }
  183. }
  184. }
  185. }
  186. else
  187. {
  188. result = string.Format("Could not determine value or item named '{0}'.", args[0]);
  189. }
  190. if (flag)
  191. {
  192. if (array.Length > 1)
  193. {
  194. result = string.Format("Player has recieved {0} of all entities from group '{1}'.", num, entityTypes);
  195. }
  196. else
  197. {
  198. result = string.Format("Player has recieved {0} of '{1}'.", num, text);
  199. }
  200. }
  201. return result;
  202. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement