예제 #1
0
 // -----------------------------------------------------------------------------------
 // GetAnimationId
 // -----------------------------------------------------------------------------------
 public static int GetAnimationId(ItemWeaponTemplate item)
 {
     if (item is ItemWeaponRangedTemplate)
     {
         return(0);
     }
     if (item is ItemWeaponMeleeTemplate)
     {
         ItemWeaponMeleeTemplate weapon = (ItemWeaponMeleeTemplate)item;
         return(weapon.animationId);
     }
     return(0);
 }
예제 #2
0
        // -----------------------------------------------------------------------------------
        // OnAttack
        // by animation event of players weapon
        // -----------------------------------------------------------------------------------
        public void OnAttack()
        {
            if (weapon == null)
            {
                return;
            }
            Player player = Obj.GetPlayer;

            if (weapon.canUse())
            {
                // -- Ranged Attack
                if (weapon.template is ItemWeaponRangedTemplate)
                {
                    ItemWeaponRangedTemplate rangedWeapon = (ItemWeaponRangedTemplate)weapon.template;
                    GameObject go = Instantiate(rangedWeapon.projectile, Obj.GetPlayer.mainCamera.transform.position, Obj.GetPlayer.mainCamera.transform.rotation);
                    go.GetComponent <Projectile>().owner = owner;
                    go.GetComponent <Projectile>().level = weapon.level;
                    weapon.depleteUsage();

                    // -- Melee Attack
                }
                else if (weapon.template is ItemWeaponMeleeTemplate)
                {
                    RaycastHit hit;
                    if (Physics.Raycast(Obj.GetPlayer.mainCamera.transform.position, Obj.GetPlayer.mainCamera.transform.TransformDirection(Vector3.forward), out hit, 4))
                    {
                        IHitable hitable = hit.collider.gameObject.GetComponent(typeof(IHitable)) as IHitable;

                        if (hitable != null)
                        {
                            ItemWeaponMeleeTemplate meleeWeapon = (ItemWeaponMeleeTemplate)weapon.template;
                            HitInfo tmp_hit = new HitInfo(meleeWeapon.damage, hit.point, true, player, weapon.level);
                            hitable.Hit(tmp_hit);
                            weapon.depleteUsage();
                        }
                    }
                }
            }
            else
            {
                UIController.Instance.ShowError(outOfAmmo);
            }
        }