public EquiptableItem EquiptItem(Item item_, bool unsheathed = false)
    {
        if (!(item_ is EquiptableItem))
        {
            return(null);
        }
        EquiptableItem            item  = item_ as EquiptableItem;
        LoadedEquiptmentPlacement toPut = (LoadedEquiptmentPlacement)item.EquiptableSlot;

        Debug.Log("[EquiptmentManager] " + item.EquiptableSlot + "_" + toPut);
        if (item is Weapon)
        {
            if (unsheathed)
            {
                toPut = LoadedEquiptmentPlacement.weaponHand;
            }
            else if (item is RangeWeapon)
            {
                toPut = LoadedEquiptmentPlacement.backSheath;
            }
            else
            {
                toPut = LoadedEquiptmentPlacement.weaponSheath;
            }
        }

        return(EquiptItem(toPut, item));
    }
Example #2
0
    public override void JobUpdate(NPC npc)
    {
        if (SubTask == CurrentSubTask.GettingEquiptment)
        {
            //If we are close to building, we get equiptment
            if (npc.Position.WithinDistance(CurrentTargetPosition, 1) && !HasEquiptment)
            {
                npc.GetLoadedEntity().SpeechBubble.PushMessage("Equipting gear");

                //Choose random valid items from work storage and equipt.
                EquiptableItem chest  = GameManager.RNG.RandomEquiptmentForSlot(WorkLocation.WorkBuilding.Inventory, EquiptmentSlot.chest);
                EquiptableItem legs   = GameManager.RNG.RandomEquiptmentForSlot(WorkLocation.WorkBuilding.Inventory, EquiptmentSlot.legs);
                EquiptableItem helm   = GameManager.RNG.RandomEquiptmentForSlot(WorkLocation.WorkBuilding.Inventory, EquiptmentSlot.head);
                Weapon         weapon = GameManager.RNG.RandomItemFromInventoryOfType <Weapon>(WorkLocation.WorkBuilding.Inventory);
                if (chest != null)
                {
                    WorkItems.Add(chest);
                    npc.EquiptmentManager.EquiptItem(LoadedEquiptmentPlacement.chest, chest);
                }
                if (legs != null)
                {
                    WorkItems.Add(legs);
                    npc.EquiptmentManager.EquiptItem(LoadedEquiptmentPlacement.legs, legs);
                }
                if (helm != null)
                {
                    WorkItems.Add(helm);
                    npc.EquiptmentManager.EquiptItem(LoadedEquiptmentPlacement.head, helm);
                }
                if (weapon != null)
                {
                    WorkItems.Add(weapon);
                    npc.EquiptmentManager.EquiptItem(LoadedEquiptmentPlacement.weaponHand, weapon);
                }
                HasEquiptment = true;
            }
        }
        else if (SubTask == CurrentSubTask.Training)
        {//if we are currently training
            if (CurrentTargetEquiptment == null)
            {
                //if equiptment is null, try and choose another
                ChooseWorkEquiptment(npc);
            }
            else
            {
                if (npc.Position.WithinDistance(CurrentTargetEquiptment.WorkPosition(), 0.5f))
                {
                    EquiptmentAssociatedTask(npc);
                }
            }
        }
    }
    /// <summary>
    /// Equipts the specified item to the specified slot
    /// Returns the item in the slot previous
    /// </summary>
    /// <param name="slot"></param>
    /// <returns></returns>
    public EquiptableItem EquiptItem(LoadedEquiptmentPlacement slot, EquiptableItem item)
    {
        EquiptableItem removed = UnequiptItem(slot);

        EquiptItems.Add(slot, item);

        Debug.Log("Item " + item + " added to slot " + slot);
        LoadedEquiptmentManager?.SetEquiptmentItem(slot, item);
        if (slot == LoadedEquiptmentPlacement.weaponHand)
        {
            Entity.CombatManager.SetEquiptWeapon(item as Weapon);
        }
        return(removed);
    }
 /// <summary>
 /// Equipts all items that are currently equipt
 /// </summary>
 /// <param name="eqMan"></param>
 private void EquiptStartItems(EquiptmentManager eqMan)
 {
     //Iterate all possible slots
     foreach (LoadedEquiptmentPlacement lep in MiscUtils.GetValues <LoadedEquiptmentPlacement>())
     {
         EquiptableItem eqIt = eqMan.GetEquiptItem(lep);
         if (eqIt != null)
         {
             SetEquiptmentItem(lep, eqIt);
         }
         else
         {
             eqIt = eqMan.GetDefaultItem(lep);
             if (eqIt != null)
             {
                 SetEquiptmentItem(lep, eqIt);
             }
         }
     }
 }
    /// <summary>
    /// Adds a new default item to its relevent slot
    /// </summary>
    /// <param name="item"></param>
    public void AddDefaultItem(EquiptableItem item)
    {
        //item must be of type default
        if (!item.IsDefault)
        {
            Debug.LogError("Default items must be of type default");
            return;
        }
        LoadedEquiptmentPlacement slot = (LoadedEquiptmentPlacement)item.EquiptableSlot;

        //Check if we have a default item in this slot already
        if (DefaultItems.ContainsKey(slot))
        {
            Debug.LogError("Entity " + Entity + " already has a default item in slot " + slot.ToString());
            return;
        }
        //If valid, we add the item
        DefaultItems.Add(slot, item);
        //If there is currently no item equipt in this slot, we equipt it
        if (GetEquiptItem(slot) == null)
        {
            LoadedEquiptmentManager?.SetEquiptmentItem(slot, item);
        }
    }