Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if (args.Length == 0)
- {
- return HelpCommand.Execute(new string[]
- {
- GiveCommand.usage
- });
- }
- PlayerEntity player = GameManager.Player;
- if (!player)
- {
- return "No active player found.";
- }
- string result = string.Empty;
- string text = args[0].ToLower();
- bool flag = false;
- bool flag2 = false;
- int num = 1;
- int loadedQuantity = 0;
- int num2 = 0;
- bool flag3 = false;
- EntityConfig[] array = null;
- EntityConfig entityConfig = null;
- EntityBehaviour entityBehaviour = null;
- InventoryItemConfig inventoryItemConfig = null;
- EntityTypes entityTypes = EntityTypes.None;
- player.Equipment.AddLuggageCase();
- if (player.Equipment.AddLoadout(text, GiveCommand.comparer))
- {
- return "Player has recieved loadout '" + text + "'.";
- }
- if (EntityManager.IsEntityTypePlural(text, out entityTypes))
- {
- if (EntityManager.TryGetAllEntityType(entityTypes, out array) > 0)
- {
- flag2 = true;
- }
- }
- else if (EntityManager.TryFindEntityType(text, out entityConfig) && entityConfig != null)
- {
- array = new EntityConfig[]
- {
- entityConfig
- };
- entityTypes = entityConfig.EntityType;
- flag2 = true;
- }
- if (flag2)
- {
- if (args.Length > 1 && int.TryParse(args[1], out num))
- {
- num = Mathf.Max(num, 1);
- flag3 = true;
- }
- if (EntityManager.TryFindEntityType(text, out entityConfig))
- {
- array = new EntityConfig[]
- {
- entityConfig
- };
- }
- if (array.Length != 0)
- {
- int num3 = num;
- int num4 = 0;
- foreach (EntityConfig entityConfig2 in array)
- {
- int num5 = num;
- while (num5 > 0 && num2 < 100)
- {
- if (entityTypes == EntityTypes.Weapons)
- {
- WeaponConfig weaponConfig = entityConfig2 as WeaponConfig;
- if (weaponConfig != null)
- {
- WeaponAmmoTypeConfig weaponAmmoTypeConfig;
- if (weaponConfig.TryGetDefaultAmmoType(out weaponAmmoTypeConfig))
- {
- inventoryItemConfig = weaponAmmoTypeConfig.ItemType;
- loadedQuantity = weaponConfig.AmmoCapacityMax;
- }
- if (weaponConfig.ItemType)
- {
- entityBehaviour = weaponConfig.ItemType.CreateEntity(player.position, player.rotation, player.Transform);
- }
- else
- {
- entityBehaviour = entityConfig2.CreateEntity(player.position, player.rotation, player.Transform);
- }
- }
- }
- else
- {
- entityBehaviour = entityConfig2.CreateEntity(player.position, player.rotation, player.Transform);
- }
- if (entityBehaviour)
- {
- switch (entityBehaviour.EntityType)
- {
- case EntityTypes.Items:
- {
- InventoryItem itemLink;
- if (entityBehaviour.TryGetComponent<InventoryItem>(out itemLink))
- {
- if (flag3)
- {
- num3 = Mathf.Min(num5, itemLink.StackCountMax);
- }
- else
- {
- num3 = 1;
- }
- num3 = Mathf.Max(num3, 1);
- itemLink.SetQuantity(num3);
- if (inventoryItemConfig)
- {
- itemLink.SetLoadedType(inventoryItemConfig);
- itemLink.SetLoadedQuantity(loadedQuantity);
- }
- if (player.Equipment.AddItem(itemLink) != ItemTransferResult.None)
- {
- flag = true;
- }
- else if (itemLink.Config.Pickup)
- {
- Vector3 position = player.mainCameraTr.position;
- Vector3 vector = player.Interact.GetWorldPoint(1f);
- vector += new Vector3(0f, 1f * (float)num4, 0f);
- Quaternion.LookRotation(position - vector, Vector3.up);
- ItemPickup itemPickup = itemLink.ConvertToPickup();
- GiveCommand.DropPickup(player, itemPickup, num4);
- num4++;
- flag = true;
- }
- else
- {
- Object.Destroy(entityBehaviour.gameObject);
- result = "Could not add '" + text + "' to inventory or drop item as pickup.";
- }
- }
- break;
- }
- case EntityTypes.Weapons:
- {
- PlayerWeapon weapon;
- if (entityBehaviour.TryGetComponent<PlayerWeapon>(out weapon) && player.Equipment.AddWeapon(weapon) != ItemTransferResult.None)
- {
- flag = true;
- }
- break;
- }
- case EntityTypes.Pickups:
- {
- ItemPickup itemPickup;
- if (entityBehaviour.TryGetComponent<ItemPickup>(out itemPickup))
- {
- InventoryItem itemLink = itemPickup.ItemLink;
- ItemTransferResult itemTransferResult = player.Equipment.AddItem(itemLink);
- if (itemTransferResult > ItemTransferResult.Partial)
- {
- if (itemTransferResult == ItemTransferResult.Complete)
- {
- itemPickup.gameObject.SetActive(false);
- }
- }
- else
- {
- GiveCommand.DropPickup(player, itemPickup, num4);
- num4++;
- }
- num3 = Mathf.Max(itemLink.Quantity, 1);
- flag = true;
- }
- break;
- }
- default:
- num5 = 0;
- break;
- }
- }
- num5 -= num3;
- num2++;
- }
- }
- }
- }
- else
- {
- result = string.Format("Could not determine value or item named '{0}'.", args[0]);
- }
- if (flag)
- {
- if (array.Length > 1)
- {
- result = string.Format("Player has recieved {0} of all entities from group '{1}'.", num, entityTypes);
- }
- else
- {
- result = string.Format("Player has recieved {0} of '{1}'.", num, text);
- }
- }
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement