/// <summary>
        /// Link to vItemManager event onUseItem to apply potion values to the leveling system mana fields.
        /// </summary>
        /// <param name="DrinkMe"></param>
        public void UsePotion(vItem DrinkMe)
        {
            if (DrinkMe.type == vItemType.Consumable)
            {                                               // ensure is a potion
                foreach (vItemAttribute viaAttrib in DrinkMe.attributes)
                {                                           // check for valid attributes
                    switch (viaAttrib.name.ToString())
                    {                                       // naming is important
                    case "Mana":
                        Mana            += viaAttrib.value; // apply the mana increase
                        ManaSlider.value = Mana;            // update the UI
                        break;

                    case "MaxMana":
                        Mana             = ManaMax; // max out the mana
                        ManaSlider.value = Mana;    // update the UI
                        break;
                    }
                }
            }
        }
        IEnumerator UnequipItemRoutine(bool flipEquip, vItem item, GameObject weapon)
        {
            ai.lockMovement = true;

            while (inUnequip || ai.actions || ai.isAttacking || ai.ragdolled)
            {
                yield return(new WaitForEndOfFrame());
            }

            if (!inEquip)
            {
                yield return(new WaitForSeconds(1));

                inUnequip = true;
                if (weapon != null && item != null)
                {
                    unequipTimer = item.enableDelayTime;
                    var type = item.type;
                    if (type != vItemType.Consumable)
                    {
                        if (!string.IsNullOrEmpty(item.DisableAnim))
                        {
                            ai.animator.SetBool("FlipEquip", flipEquip);
                            ai.animator.CrossFade(item.DisableAnim, 0.25f);
                        }
                    }
                    if (weapon != null)
                    {
                        while (unequipTimer > 0)
                        {
                            unequipTimer -= Time.deltaTime;
                            yield return(new WaitForEndOfFrame());
                        }
                        weapon.SetActive(false);
                    }
                }
                inUnequip = false;
            }
            ai.lockMovement = true;
        }
Exemplo n.º 3
0
 /// <summary>
 /// Occurs when the AI uses a vItem.
 /// </summary>
 /// <param name="item">vItem that has been used, drunk etc...</param>
 public void UseItem(vItem item)
 {
     if (item)
     {
         onUseItem.Invoke(item);
         if (item.attributes != null && item.attributes.Count > 0 && applyAttributeEvents.Count > 0)
         {
             foreach (ApplyAttributeEvent attributeEvent in applyAttributeEvents)
             {
                 var attributes = item.attributes.FindAll(a => a.name.Equals(attributeEvent.attribute));
                 foreach (vItemAttribute attribute in attributes)
                 {
                     attributeEvent.onApplyAttribute.Invoke(attribute.value);
                 }
             }
         }
         if (item.amount <= 0 && items.Contains(item))
         {
             items.Remove(item);
         }
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// Occurs when an vItem has been dropped by the AI.
 /// </summary>
 /// <param name="item">Item that has been dropped.</param>
 /// <param name="amount">Amount that has been dropped.</param>
 public void DropItem(vItem item, int amount)
 {
     item.amount -= amount;
     if (item.dropObject != null)
     {
         var             dropObject = Instantiate(item.dropObject, transform.position, transform.rotation) as GameObject;
         vItemCollection collection = dropObject.GetComponent <vItemCollection>();
         if (collection != null)
         {
             collection.items.Clear();
             var itemReference = new ItemReference(item.id);
             itemReference.amount     = amount;
             itemReference.attributes = new List <vItemAttribute>(item.attributes);
             collection.items.Add(itemReference);
         }
     }
     onDropItem.Invoke(item, amount);
     if (item.amount <= 0 && items.Contains(item))
     {
         items.Remove(item);
         Destroy(item);
     }
 }
Exemplo n.º 5
0
        IEnumerator UnequipItemRoutine(bool flipID, vItem item, GameObject weapon)
        {
            ai.lockMovement = true;

            while (inUnequip || ai.actions || ai.isAttacking || ai.ragdolled)
            {
                yield return(new WaitForEndOfFrame());
            }

            if (!inEquip)
            {
                yield return(new WaitForSeconds(1));

                inUnequip = true;
                if (weapon != null && item != null)
                {
                    unequipTimer = item.equipDelayTime;
                    var type = item.type;
                    if (type != vItemType.Consumable)
                    {
                        ai.animator.SetInteger("EquipItemID", flipID ? -item.EquipID : item.EquipID);
                        ai.animator.SetTrigger("EquipItem");
                    }
                    if (weapon != null)
                    {
                        while (unequipTimer > 0)
                        {
                            unequipTimer -= Time.deltaTime;
                            yield return(new WaitForEndOfFrame());
                        }
                        weapon.SetActive(false);
                    }
                }
                inUnequip = false;
            }
            ai.lockMovement = true;
        }
Exemplo n.º 6
0
    public void OnEquip(vItem item)
    {
        var damage       = item.attributes.Find(attribute => attribute.name == Invector.ItemManager.vItemAttributes.Damage);
        var staminaCost  = item.attributes.Find(attribute => attribute.name == Invector.ItemManager.vItemAttributes.StaminaCost);
        var defenseRate  = item.attributes.Find(attribute => attribute.name == Invector.ItemManager.vItemAttributes.DefenseRate);
        var defenseRange = item.attributes.Find(attribute => attribute.name == Invector.ItemManager.vItemAttributes.DefenseRange);

        if (damage != null)
        {
            this.damage.damageValue = damage.value;
        }
        if (staminaCost != null)
        {
            this.staminaCost = staminaCost.value;
        }
        if (defenseRate != null)
        {
            this.defenseRate = defenseRate.value;
        }
        if (defenseRange != null)
        {
            this.defenseRange = defenseRate.value;
        }
    }
Exemplo n.º 7
0
 public void OnUnequip(vItem item)
 {
     this.item = null;
 }
        /// <summary>
        /// vItem to GUIContent.
        /// </summary>
        /// <param name="item"></param>
        /// <returns>Icon from the vItem</returns>
        GUIContent GetItemContent(vItem item)
        {
            var texture = item.icon != null ? item.icon.texture : null;

            return(new GUIContent(item.name, texture, item.description));;
        }
Exemplo n.º 9
0
        /// <summary>
        /// Initialise listeners and component references.
        /// </summary>
        protected virtual void Start()
        {
            // initialise invector AI handling
            player    = GlobalFuncs.FindPlayerInstance();
            agent     = GetComponent <NavMeshAgent>();
            animator  = GetComponent <Animator>();
            inventory = GetComponent <MagicAIItemManager>();
#if !VANILLA
            ai = GetComponent <v_AIController>();
            if (ai)
            {                                                          // don't start if invector AI and all components are not present
                // invector ai event handlers
                ai.onReceiveDamage.AddListener(OnReceiveDamage_Chase); // listen for damage to enable chase when out of FOV
                ai.onChase.AddListener(delegate { OnChase(); });       // listen for start of chase mode
                ai.onIdle.AddListener(delegate { OnIdle(); });         // listen for start of idle mode
                //ai.onPatrol.AddListener(delegate { OnPatrol(); });  // listen for start of idle mode
                ai.onDead.AddListener(delegate { OnDead(); });         // listen for sudden death

                // store original FOV
                fOriginal_maxDetectDistance    = ai.maxDetectDistance;
                fOriginal_distanceToLostTarget = ai.distanceToLostTarget;
                fOriginal_fieldOfView          = ai.fieldOfView;
            }
#else
            // handle non invector events
#endif

            // add a listener to the leveling component if available
            CharacterBase levelingSystem = GetComponentInParent <CharacterBase>();
            if (levelingSystem)
            {
                useMana = new SetIntValue(levelingSystem.UseMana);
                levelingSystem.NotifyUpdateHUD += new CharacterBase.UpdateHUDHandler(UpdateHUDListener);
                levelingSystem.ForceUpdateHUD();
            }

#if !VANILLA
            // make short list of spells in inventory
            if (inventory && AnimatorTrigger.Length > 0 && HasMagicAbilities)
            {
                SpellsShortList = new List <MagicAIAvailableSpell>();                        // init the list
                foreach (ItemReference ir in inventory.startItems)
                {                                                                            // process all start items
                    vItem item = inventory.itemListData.items.Find(t => t.id.Equals(ir.id)); // find the vItem by id
                    if (item.type == vItemType.Spell)
                    {                                                                        // only after spells
                        SpellsShortList.Add(new MagicAIAvailableSpell()
                        {
                            MagicID  = item.attributes.Find(ia => ia.name.ToString() == "MagicID").value,
                            ManaCost = item.attributes.Find(ia => ia.name.ToString() == "ManaCost").value
                        });  // add to the short list
                    }
                }
                if (SpellsShortList.Count == 0)
                {                           // none found
                    SpellsShortList = null; // reset back to null for fast checking
                    if (GlobalFuncs.DEBUGGING_MESSAGES)
                    {
                        Debug.Log("Warning spells NOT found in magic AI inventory");
                    }
                }
            }
#endif

            // birth animation & magic spawning
            if (BirthStartTrigger != "")
            {                                                                                                                                                                                                                   // birth animation specified
                animator.SetTrigger(BirthStartTrigger);                                                                                                                                                                         // trigger the random magic state selector
            }
            CoDelayedSpawn = StartCoroutine(GlobalFuncs.SpawnAllDelayed(SpawnOnBirth, BirthSpawnDelay, NoneSequentialSpawns, transform, null, 0, false, (gameObject.tag == "Enemy" ? SpawnTarget.Friend : SpawnTarget.Enemy))); // trigger all birth spawns the the array
        }
Exemplo n.º 10
0
 public InventoryPlacement(int inputAreaIndex, int inputSlotIndex, vItem inputItem)
 {
     this.areaIndex = inputAreaIndex;
     this.slotIndex = inputSlotIndex;
     this.item      = inputItem;
 }
Exemplo n.º 11
0
 public void OnUnequip(vItem item)
 {
 }
Exemplo n.º 12
0
        /// <summary>
        /// Load a save game from the abstract data layer.
        /// </summary>
        /// <param name="LevelingSystem">Leveling system to load into.</param>
        /// <param name="SaveGameID">ID of the save game to load.</param>
        /// <returns>Name of scene to load.</returns>
        public string LoadPlayerState(ref CharacterBase LevelingSystem, int SaveGameID)
        {
            try
            {
                // load the header values
                string SceneName = "EDITOR";
                List <SimpleDataHeader> HeaderData = BuildHeaderDataBlock(ref LevelingSystem, true);
                LoadHeader(SaveGameID, ref SceneName, ref HeaderData);

                // process the data into the leveling system
                foreach (SimpleDataHeader sdh in HeaderData)
                {
                    switch (sdh.Name)
                    {
                    case "CharacterName":
                        LevelingSystem.Name = sdh.Value;
                        break;

                    case "Axis":
                        LevelingSystem.CurrentAxis = (BaseAxis)Convert.ToInt32(sdh.Value);
                        break;

                    case "Alignment":
                        LevelingSystem.CurrentAlignment = (BaseAlignment)Convert.ToInt32(sdh.Value);
                        break;

                    case "Race":
                        LevelingSystem.CurrentRace = (BaseRace)Convert.ToInt32(sdh.Value);
                        break;

                    case "Class":
                        LevelingSystem.CurrentClass = (BaseClass)Convert.ToInt32(sdh.Value);
                        break;

                    case "Level":
                        LevelingSystem.CurrentLevel = Convert.ToInt32(sdh.Value);
                        break;

                    case "XP":
                        LevelingSystem.CurrentXP = Convert.ToInt32(sdh.Value);
                        break;

                    case "UnspentSkillPoints":
                        LevelingSystem.UnspentSkillPoints = Convert.ToInt32(sdh.Value);
                        break;
                    }
                }

                // load all attributes
                for (int i = 0; i < LevelingSystem.Skills.Count; i++)
                {
                    LevelingSystem.Skills[i].Value = LoadAttribute(SaveGameID, 100 + (int)LevelingSystem.Skills[i].Skill);
                }
                for (int i = 0; i < LevelingSystem.Resist.Count; i++)
                {
                    LevelingSystem.Resist[i].Value = LoadAttribute(SaveGameID, 200 + (int)LevelingSystem.Resist[i].Resist);
                }
                for (int i = 0; i < LevelingSystem.Collectables.Count; i++)
                {
                    LevelingSystem.Collectables[i].Value = LoadAttribute(SaveGameID, 300 + (int)LevelingSystem.Collectables[i].Type);
                }

#if !VANILLA
                // then load equip display slots
                for (int i = 0; i < Inventory.changeEquipmentControllers.Count; i++)
                {
                    int EquipedItemID = (int)LoadAttribute(SaveGameID, 600 + i);  // load from data layer
                    if (EquipedItemID > 0)
                    {
                        var reference = new ItemReference(EquipedItemID - 1);
                        reference.amount    = 1;
                        reference.autoEquip = true;
                        reference.indexArea = i;
                        ItemManager.AddItem(reference, true);
                    }
                }

                // load inventory
                if (Inventory && ItemListData)
                {
                    Inventory.items.Clear();
                    foreach (vItem vi in ItemListData.items)
                    {
                        vi.amount = (int)LoadAttribute(SaveGameID, 1000 + vi.id);
                        if (vi.amount > 0)
                        {
                            Inventory.items.Add(vi);
                        }
                    }

                    // also load equipped melee weapons & consumables
                    for (int i = 0; i < Inventory.equipAreas.Length; i++)
                    {
                        var equipArea = Inventory.equipAreas[i];
                        var validSlot = equipArea.ValidSlots;
                        for (int a = 0; a < validSlot.Count; a++)
                        {
                            int EquipedItemID = (int)LoadAttribute(SaveGameID, 500 + (i * 10) + a);   // load from data layer
                            if (EquipedItemID > 0)
                            {                                                                         // found equipped item id
                                vItem vi = ItemListData.items.Find(e => e.id == (EquipedItemID - 1)); // search
                                if (vi)
                                {                                                                     // found the id in the item list data
                                    validSlot[a].AddItem(vi);                                         // add to slot
                                }
                            }
                        }
                    }
                }
#endif

                // spell triggers
                if (Settings)
                {
                    for (int s = 0; s < Settings.SpellsTriggers.Count; s++)
                    {  // check all triggers
                        MagicSpellTrigger st = Settings.SpellsTriggers[s];
#if !VANILLA
                        if (st.Input.useInput)
                        {                                                                                                    // enabled
                            for (int i = 0; i < st.EquipSlots.Length; i++)
                            {                                                                                                // check all equip slots for this trigger
                                int ID = (int)LoadAttribute(SaveGameID, 400 + (s * 10) + i);                                 // attempt load
                                if (ID > 0)
                                {                                                                                            // found in data layer?
                                    vItem viSpell = ItemListData.items.Find(v => v.id == (ID - 1));                          // attempt find vItem in collection, ID is -1 as LoadReterns 0 for not found
                                    if (viSpell)
                                    {                                                                                        // spell item id found?
                                        st.EquipSlots[i].AddItem(viSpell);                                                   // update inventory slot
                                        st.MagicId  = viSpell.attributes.Find(ia => ia.name.ToString() == "MagicID").value;  // grab the magic id
                                        st.ManaCost = viSpell.attributes.Find(ia => ia.name.ToString() == "ManaCost").value; // grab the mana cost
                                        st.EquipDisplay.AddItem(viSpell);                                                    // update the slot with the spell icon
                                    }
                                }
                            }
                        }
#endif
                    }
                }

                // order recalc
                LevelingSystem.reCalcCore(true);

                // return scene to load
                return(SceneName);
            }
            catch (Exception ex)
            {
                if (GlobalFuncs.DEBUGGING_MESSAGES)
                {
                    Debug.Log("LoadPlayerState(" + LevelingSystem.Name + "," + SaveGameID.ToString() + ") " + ex.Message);
                }
                return("");
            }
            finally
            {  // ensure clean up happens, even on error
                CleanUp();
            }
        }