/// <summary> /// Initialize the default values. /// </summary> private void Start() { m_Health = GetComponent <Health>(); m_Inventory = GetComponent <InventoryBase>(); // Find the ItemType. var itemType = m_Inventory.DefaultLoadout[0].ItemType; var item = m_Inventory.GetItem(0, itemType); // If the first DefaultLoadout element is an item then the consumable ItemType should be retrieved. if (item != null) { var itemActions = item.ItemActions; for (int i = 0; i < itemActions.Length; ++i) { var usableItem = itemActions[i] as Items.Actions.IUsableItem; if (usableItem != null) { m_ItemType = usableItem.GetConsumableItemType(); break; } } } else { m_ItemType = itemType; } }
private void RestoreItems(bool restoreEquipped, ItemCollection itemCollection, InventoryBase inventory, HashSet <ItemType> alreadyAddedItemTypes) { for (int i = 0; i < data.items.Count; i++) { var itemData = data.items[i]; if (itemData.count == 0) { continue; } if (itemData.equipped != restoreEquipped) { continue; } var itemType = UCCUtility.GetItemType(itemCollection, itemData.itemID); inventory.PickupItemType(itemType, itemData.count, itemData.slot, true, restoreEquipped); var item = inventory.GetItem(itemData.slot, itemType); if (item == null) { continue; } for (int j = 0; j < item.ItemActions.Length; j++) { var usableItem = item.ItemActions[j] as UsableItem; if (usableItem == null) { continue; } for (int k = 0; k < itemData.itemActionData.Count; ++k) { if (usableItem.ID != itemData.itemActionData[k].id) { continue; } #if ULTIMATE_CHARACTER_CONTROLLER_SHOOTER var shootableWeapon = usableItem as ShootableWeapon; if (shootableWeapon != null) { // Temporarily fill clip so inventory.PickupItemType doesn't auto-reload: usableItem.SetConsumableItemTypeCount(shootableWeapon.ClipSize); } #endif if (debug) { Debug.Log("UCC Saver on " + name + " restoring item: " + usableItem.name + " (" + itemData.itemActionData[k].consumableCount + "/" + itemData.itemActionData[k].count + ")", this); } var consumableItemType = usableItem.GetConsumableItemType(); if (itemData.itemActionData[k].count > 0 && !alreadyAddedItemTypes.Contains(consumableItemType)) { inventory.PickupItemType(consumableItemType, itemData.itemActionData[k].count, -1, true, false); alreadyAddedItemTypes.Add(consumableItemType); } usableItem.SetConsumableItemTypeCount(itemData.itemActionData[k].consumableCount); } } } }
protected static int GetItemSlot(InventoryBase inventory, ItemType itemType) { if (inventory != null && itemType != null) { for (int i = 0; i < inventory.SlotCount; i++) { var item = inventory.GetItem(i); if (item != null && item.ItemType == itemType) { return(i); } } } return(-1); }
/// <summary> /// Moves the item in each slot. /// </summary> private void FixedUpdate() { var lookVector = m_PlayerInput.GetLookVector(false); for (int i = 0; i < m_Inventory.SlotCount; ++i) { var item = m_Inventory.GetItem(i); if (item != null && item.IsActive() && item.DominantItem) { item.Move(lookVector.x, lookVector.y); } } // Each object should only be updated once. Clear the frame after execution to allow the objects to be updated again. UnityEngineUtility.ClearUpdatedObjects(); }
/// <summary> /// A player has entered the room. Ensure the joining player is in sync with the current game state. /// </summary> /// <param name="player">The Photon Player that entered the room.</param> /// <param name="character">The character that the player controls.</param> private void OnPlayerEnteredRoom(Player player, GameObject character) { if (m_Inventory != null) { // Notify the joining player of the ItemTypes that the player has within their inventory. var items = m_Inventory.GetAllItems(); for (int i = 0; i < items.Count; ++i) { var item = items[i]; photonView.RPC("PickupItemTypeRPC", player, item.ItemType.ID, m_Inventory.GetItemTypeCount(item.ItemType)); if (item.DropPrefab != null) { // Usable Items have a separate ItemType count. var itemActions = item.ItemActions; for (int j = 0; j < itemActions.Length; ++j) { var usableItem = itemActions[j] as IUsableItem; if (usableItem == null) { continue; } var consumableItemTypeCount = usableItem.GetConsumableItemTypeCount(); if (consumableItemTypeCount > 0 || consumableItemTypeCount == -1) // -1 is used by the grenade to indicate that there is only one item. { photonView.RPC("PickupUsableItemActionRPC", player, item.ItemType.ID, item.SlotID, itemActions[j].ID, m_Inventory.GetItemTypeCount(usableItem.GetConsumableItemType()), usableItem.GetConsumableItemTypeCount()); } } } } // Ensure the correct item is equipped in each slot. for (int i = 0; i < m_Inventory.SlotCount; ++i) { var item = m_Inventory.GetItem(i); if (item == null) { continue; } photonView.RPC("EquipUnequipItemRPC", player, item.ItemType.ID, i, true); } } // ULTIMATE_CHARACTER_CONTROLLER_MULTIPLAYER will be defined, but it is required here to allow the addon to be compiled for the first time. #if ULTIMATE_CHARACTER_CONTROLLER_MULTIPLAYER // The remote character should have the same abilities active. for (int i = 0; i < m_CharacterLocomotion.ActiveAbilityCount; ++i) { var activeAbility = m_CharacterLocomotion.ActiveAbilities[i]; photonView.RPC("StartAbilityRPC", player, activeAbility.Index, activeAbility.GetNetworkStartData()); } for (int i = 0; i < m_CharacterLocomotion.ActiveItemAbilityCount; ++i) { var activeItemAbility = m_CharacterLocomotion.ActiveItemAbilities[i]; photonView.RPC("StartItemAbilityRPC", player, activeItemAbility.Index, activeItemAbility.GetNetworkStartData()); } #endif }
/// <summary> /// Tries to start or stop the camera zoom. The camera may not be able to start if an ability doesn't allow it. /// </summary> /// <param name="zoom">Should the camera zoom?</param> public void TryZoom(bool zoom) { if (m_Character == null || !m_Character.activeInHierarchy) { return; } // The zoom state may not be able to start. Remember the input so when the game state changes (different ability, item, etc) zoom can try to activate again. m_ZoomInput = zoom; if (m_ZoomInput) { // The camera may not allow zooming. if (!m_CanZoom) { SetZoom(false); return; } // The ViewType may not allow zoomig. if (!m_ViewType.CanZoom()) { SetZoom(false); return; } // The item may not allow zooming. if (m_CharacterInventory != null) { for (int i = 0; i < m_CharacterInventory.SlotCount; ++i) { var item = m_CharacterInventory.GetItem(i); if (item != null && !item.CanCameraZoom()) { SetZoom(false); return; } } } // The character abilities disallow zoom. if (m_CharacterLocomotion.ActiveAbilityCount > 0) { for (int i = 0; i < m_CharacterLocomotion.ActiveAbilityCount; ++i) { if (!m_CharacterLocomotion.ActiveAbilities[i].CanCameraZoom()) { SetZoom(false); return; } } } if (m_CharacterLocomotion.ActiveItemAbilityCount > 0) { for (int i = 0; i < m_CharacterLocomotion.ActiveItemAbilityCount; ++i) { if (!m_CharacterLocomotion.ActiveItemAbilities[i].CanCameraZoom()) { SetZoom(false); return; } } } } // The camera can zoom or unzoom. SetZoom(zoom); }