public void EquipArmor(Item itemToEquip)
    {
        SoundDatabase.PlaySound(0);
        foreach (Transform item in playerArmor.transform)
        {
            Item checkItem = item.GetComponent <ItemHolder>().item;
            if (checkItem.ItemType == itemToEquip.ItemType)
            {
                UnequipArmor(checkItem);
                Destroy(item.gameObject);
            }
        }
        Armor armor = Instantiate(Resources.Load <Armor>("Prefabs/Items/" + itemToEquip.Name));

        armor.transform.SetParent(playerArmor.transform);
        armor.transform.localScale = new Vector3(1, 1, 1);
        //GameObject armor = new GameObject();
        //armor.AddComponent<ItemHolder>();
        //armor.GetComponent<ItemHolder>().item = itemToEquip;
        //armor.AddComponent<SpriteRenderer>();
        //armor.GetComponent<SpriteRenderer>().sprite = Resources.Load<Sprite>("Icons/PlayerEquips/" + itemToEquip.Name);
        //armor.GetComponent<SpriteRenderer>().sortingOrder = 10;
        armor.name = itemToEquip.Name;
        //armor.transform.SetParent(playerArmor.transform);
        armor.transform.localPosition = new Vector3(0, 0, 0);
        //armor.transform.localScale = new Vector3(1, 1, 1);
        //
        itemToEquip.Stats.AddStatsToOther(player.Stats);
        //equippedWeapon = EquippedWeapon.GetComponent<IArmor>();
        //itemToEquip.Stats = itemToEquip.Stats;
        UIEventHandler.ItemEquipped(itemToEquip);
        UIEventHandler.StatsChanged();
    }
Ejemplo n.º 2
0
    public void EquipWeapon(Item itemToEquip)
    {
        if (EquippedWeapon != null)
        {
            UnequipWeapon();
        }

        EquippedWeapon = (GameObject)Instantiate(Resources.Load <GameObject>("Weapons/" + itemToEquip.ObjectSlug),
                                                 playerHand.transform);
        equippedWeapon = EquippedWeapon.GetComponent <IWeapon>();
        if (EquippedWeapon.GetComponent <IProjectileWeapon>() != null)
        {
            EquippedWeapon.GetComponent <IProjectileWeapon>().ProjectileSpawn = spawnProjectile;
        }
        //EquippedWeapon.transform.SetParent(playerHand.transform);
        equippedWeapon.Stats  = itemToEquip.BaseStats;
        currentlyEquippedItem = itemToEquip;
        characterStats.AddStatBonus(itemToEquip.BaseStats);
        if (itemToEquip.RndSuffixStats != null)
        {
            characterStats.AddStatBonus(itemToEquip.RndSuffixStats);
        }
        UIEventHandler.ItemEquipped(itemToEquip);
        UIEventHandler.StatsChanged();
    }
    public void EquipWeapon(Item itemToEquip)
    {
        /* This is where we destroy the item in the players hand to swap/remove weapons. */
        if (EquippedWeapon != null)
        {
            UnequipWeapon();
        }
        /* Going inside our 'Resources' folder and searching our weapon  */
        EquippedWeapon = Instantiate(Resources.Load <GameObject>("Weapons/" + itemToEquip.ObjectSlug),
                                     playerHand.transform.position, playerHand.transform.rotation);

        /* And we now know that this equipped weapon will contain stas from IWeapon*/
        equippedWeapon = EquippedWeapon.GetComponent <IWeapon>();

        /* Not all weapons are projectile weapons, hence we need to check the type of weapon is being equipped. */
        if (EquippedWeapon.GetComponent <IProjectileWeapon>() != null)
        {
            EquippedWeapon.GetComponent <IProjectileWeapon>().ProjectileSpawn = spawnProjectile;
        }
        /* Setting Parent to parent it to playersHand (changes Parents) and becomes parented to players hand. */
        EquippedWeapon.transform.SetParent(playerHand.transform);
        equippedWeapon.Stats  = itemToEquip.Stats;
        currentlyEquippedItem = itemToEquip;
        /* After equipping, we add the stat bonuses. */
        characterStats.AddStatsBonus(itemToEquip.Stats);
        UIEventHandler.ItemEquipped(itemToEquip);
        UIEventHandler.StatsChanged();
    }
Ejemplo n.º 4
0
 public void EquipWeapon(Item itemToEquip)
 {
     if (EquippedWeapon != null)                                 //判断当前是否有武器
     {
         characterStats.RemoveStatBonus(equippedWeapon.Stats);   //移除该武器的属性增益
         Destroy(EquippedWeapon.transform.gameObject);
     }
     EquippedWeapon = (GameObject)Instantiate(Resources.Load <GameObject>("Weapons/" + itemToEquip.ObjectSlug),
                                              playerHand.transform.position, playerHand.transform.rotation);
     equippedWeapon = EquippedWeapon.GetComponent <IWeapon>();    //获得武器接口
     //判断是否法杖武器
     if (EquippedWeapon.GetComponent <IProjectileWeapon>() != null)
     {
         //设定法球生成位置
         EquippedWeapon.GetComponent <IProjectileWeapon>().ProjectlitSpawn = spawnProjectile;
     }
     //判断是否枪械武器
     if (EquippedWeapon.GetComponent <IGun>() != null)
     {
         //设置子弹生成位置
         EquippedWeapon.GetComponent <IGun>().ProjectlitSpawn = bulletSpawn;
     }
     EquippedWeapon.transform.SetParent(playerHand.transform);
     equippedWeapon.Stats  = itemToEquip.stats;
     currentlyEquippedItem = itemToEquip;
     characterStats.AddStatBonus(itemToEquip.stats);             //实现武器带来的属性增益
     UIEventHandler.ItemEquipped(itemToEquip);                   //UI事件驱动
     UIEventHandler.StatsChanged();                              //UI事件驱动
 }
    public void EquipWeapon(Item itemToEquip)
    {
        if (EquippedWeapon != null)
        {
            InventoryController.Instance.GiveItem(currentlyEquippedItem.ObjectSlug);
            charactersStats.RemoveBonusStats(EquippedWeapon.GetComponent <IWeapon>().Stats); //Remove current weapon's stats from player
            Destroy(playerHand.transform.GetChild(0).gameObject);                            //Destroy the current weapon on player's hand
        }

        EquippedWeapon = (GameObject)Instantiate(Resources.Load <GameObject>("Weapons/" + itemToEquip.ObjectSlug), playerHand.transform.position, playerHand.transform.rotation);
        //Get the prefab named "Sword" from the "Resources" folder and set the weapon to the player's hand
        //The item is named "Sword" in InventoryController and this line will get the exact prefab for it

        equippedWeapon = EquippedWeapon.GetComponent <IWeapon>();

        if (EquippedWeapon.GetComponent <IProjectileWeapon>() != null) //Sword can't cast fireball
        {
            EquippedWeapon.GetComponent <IProjectileWeapon>().ProjectileSpawn = spawnProjectile;
        }

        EquippedWeapon.transform.SetParent(playerHand.transform); //Parent to the player's hand

        equippedWeapon.Stats = itemToEquip.Stats;                 //EquippedWeapon.GetComponent<IWeapon>().Stats; //Get stats from the weapon

        currentlyEquippedItem = itemToEquip;

        charactersStats.AddBonusStats(itemToEquip.Stats);

        UIEventHandler.ItemEquipped(itemToEquip);
        UIEventHandler.StatsChanged();
    }
Ejemplo n.º 6
0
    public void EquipWeapon(Item itemToEquip)
    {
        if (EquippedWeapon != null)
        {
            InventoryController.Instance.GiveItem(currentlyEquippedItem.ObjectSlug);

            characterStats.RemoveStatBonus(EquippedWeapon.GetComponent <IWeapon>().Stats);
            Destroy(playerHand.transform.GetChild(0).gameObject);
        }

        EquippedWeapon = Instantiate((GameObject)Resources.Load("Prefabs/Items/Weapons/" + itemToEquip.ObjectSlug), playerHand.transform.position, playerHand.transform.rotation);

        equippedWeapon = EquippedWeapon.GetComponent <IWeapon>();

        if (EquippedWeapon.GetComponent <IProjectileWeapon>() != null)
        {
            EquippedWeapon.GetComponent <IProjectileWeapon>().ProjectileSpawn = spawnProjectile;
        }

        EquippedWeapon.transform.SetParent(playerHand.transform);

        currentlyEquippedItem = itemToEquip;

        equippedWeapon.Stats = itemToEquip.Stats;

        characterStats.AddStatBonus(itemToEquip.Stats);

        UIEventHandler.ItemEquipped(itemToEquip);
        UIEventHandler.StatsChanged(characterStats);
    }
Ejemplo n.º 7
0
 public void EquipItem(Item itemToEquip)
 {
     playerWeaponController.EquipWeapon(itemToEquip);
     RemoveItemFromInventory(itemToEquip);
     UIEventHandler.ItemEquipped(itemToEquip);
     equippedItem = itemToEquip;
     isEquipped   = true;
 }
Ejemplo n.º 8
0
    public void EquipWeapon(Item itemToEquip)
    {
        if (EquippedWeapon != null)
        {
            UnEquipWeapon();
        }

        EquippedWeapon = (GameObject)Instantiate(Resources.Load <GameObject>("Items/Weapons/" + itemToEquip.ObjectSlug), playerHand.transform.position, playerHand.transform.rotation);
        equippedWeapon = EquippedWeapon.GetComponent <IWeapon>();
        EquippedWeapon.transform.SetParent(playerHand.transform);
        equippedWeapon.Stats  = itemToEquip.Stats;
        currentlyEquippedItem = itemToEquip;
        characterStats.AddStatBonus(itemToEquip.Stats);
        UIEventHandler.ItemEquipped(itemToEquip);
        UIEventHandler.StatsChanged();
    }
Ejemplo n.º 9
0
    public void EquipItem(Equippable itemToEquip)
    {
        Debug.Log("Checking " + itemToEquip.Slot + " for existing equipment...");

        if (equippedItems.Exists(x => x.Slot == itemToEquip.Slot))
        {
            Equippable previouslyEquipped = equippedItems.Find(x => x.Slot == itemToEquip.Slot);
            UnEquipItem(previouslyEquipped);
        }

        Debug.Log("Equipping " + itemToEquip.name + "... ");
        if (baggedItems.Remove(itemToEquip))            //is the item coming from the player's own inventory?
        {
            UIEventHandler.ItemRemovedFromInventory(itemToEquip);
        }

        foreach (EquippableModel x in itemToEquip.Models)
        {
            GameObject modelAnchor = FindEquipmentSlot(transform.root.Find("PlayerModel").gameObject, (itemToEquip.Slot + x.Side));
            x.transform.SetParent(modelAnchor.transform, false);
            x.OrientForSlot();
            x.GetComponent <MeshRenderer>().enabled = true;

            // Check if model is projectile weapon
            if (x.gameObject.GetComponent <IWeapon>() != null)
            {
                playerWeaponController.equippedIWeapon = x.gameObject.GetComponent <IWeapon>();
                if (x.gameObject.GetComponent <IProjectileWeapon>() != null)
                {
                    Debug.Log(x.gameObject + " is a projectile weapon.");
                    x.gameObject.GetComponent <IProjectileWeapon>().ProjectileSpawn = playerWeaponController.projectileSpawn;
                    Debug.Log(x + "'s ProjectileSpawn is set to " + playerWeaponController.projectileSpawn + ".");
                }
            }
        }

        equippedItems.Add(itemToEquip);
        UIEventHandler.ItemEquipped(itemToEquip);
        characterStats.AddStatBonuses(itemToEquip.Stats);

        Debug.Log("Equipped: " + itemToEquip);
    }
 public void EquipWeapon(Item itemToEquip)
 {
     UnequipWeapon(itemToEquip);
     EquippedWeapon = Instantiate(Resources.Load <GameObject>("Prefabs/Items/" + itemToEquip.Name), playerHand.transform);
     if (EquippedWeapon.GetComponent <IProjectileWeapon>() != null)
     {
         EquippedWeapon.GetComponent <IProjectileWeapon>().ProjectileSpawn = spawnProjectile;
     }
     itemToEquip.Stats.AddStatsToOther(player.Stats);
     equippedWeapon        = EquippedWeapon.GetComponent <Weapon>();
     equippedWeapon.Stats  = itemToEquip.Stats;
     currentlyEquippedItem = itemToEquip;
     EquippedWeapon.transform.SetParent(playerHand.transform);
     //EquippedWeapon.transform.localScale = new Vector3(1, 1, 1);
     equippedWeapon.playerSkillController = playerSkillController;
     equippedWeapon.player = player.Stats;
     equippedWeapon.SetAttackSpeed(player.Stats.AttackSpeed);
     SoundDatabase.PlaySound(0);
     UIEventHandler.ItemEquipped(itemToEquip);
     UIEventHandler.StatsChanged();
 }
Ejemplo n.º 11
0
    public void EquipWeapon(Item itemToEquip)
    {
        if (EquippedWeapon != null)
        {
            InventoryController.Instance.GiveItem(currentlyEquippedWeapon.ObjectSlug);
            characterStats.RemoveStatBonus(EquippedWeapon.GetComponent <IWeapon>().Stats);
            Destroy(playerHand.transform.GetChild(0).gameObject);
        }

        EquippedWeapon = Instantiate(Resources.Load <GameObject>("Weapons/" + itemToEquip.ObjectSlug),
                                     playerHand.transform.position, playerHand.transform.rotation);

        equippedWeapon = EquippedWeapon.GetComponent <IWeapon>();

        //스테프일때
        if (EquippedWeapon.GetComponent <IProjectileWeapon>() != null)
        {
            //무기에 spawnProjectile을 넣어둔다
            EquippedWeapon.GetComponent <IProjectileWeapon>().ProjectileSpawn = spawnProjectile;
        }
        else if (EquippedWeapon.GetComponent <Sword>() != null)
        {
            EquippedWeapon.GetComponent <Sword>().CharacterStats = characterStats;
        }

        EquippedWeapon.transform.SetParent(playerHand.transform);

        equippedWeapon.Stats = itemToEquip.Stats;

        currentlyEquippedWeapon = itemToEquip;

        List <BaseStat> tmpBase = itemToEquip.Stats;

        characterStats.AddStatBonus(tmpBase);

        UIEventHandler.ItemEquipped(itemToEquip);
    }
Ejemplo n.º 12
0
    public void EquipWeapon(Item itemToEquip)
    {
        Item previousWeaponItem = currentlyEquipedWeaponItem;

        UnequipCurrentWeapon();
        currentlyEquipedWeaponItem = itemToEquip;

        equippedWeapon = (GameObject)Instantiate(
            Resources.Load("Weapons/" + itemToEquip.ObjectSlug),
            playerHand.transform.position,
            playerHand.transform.rotation
            );


        weaponComponent = equippedWeapon.GetComponent <IWeapon>();

        if (equippedWeapon.GetComponent <IProjectileWeapon>() != null)
        {
            equippedWeapon.GetComponent <IProjectileWeapon>().projectileSpawn = spawnProjectile;
        }


        equippedWeapon.GetComponent <IWeapon>().Stats = itemToEquip.Stats;
        equippedWeapon.transform.SetParent(playerHand.transform, false);

        Animator animator = equippedWeapon.GetComponent <Animator>();

        if (animator != null)
        {
            animator.enabled = true;
        }

        characterStats.AddStatBonus(itemToEquip.Stats);

        UIEventHandler.ItemEquipped(currentlyEquipedWeaponItem);
        UIEventHandler.StatsChanged();
    }