示例#1
0
        public bool OnSwingImpact()
        {
            WaitingForImpact = false;

            if (!HasWorldItem)
            {
                return(false);
            }

            mThingToHit    = null;
            mBodyPartToHit = player.Surroundings.ClosestBodyPartInRange;;
            if (player.Focus.IsFocusingOnSomething)
            {
                mThingToHit = player.Focus.LastFocusedObject;
            }
            else if (player.Surroundings.IsSomethingInRange)
            {
                mThingToHit = player.Surroundings.ClosestObjectInRange;
                if (player.Surroundings.IsWorldItemInRange)
                {
                    //give priority to world items over other stuff
                    //TODO verify this
                    mThingToHit = player.Surroundings.WorldItemFocus;
                }
            }

            if (mThingToHit != null)
            {
                DamagePackage damage = null;
                Vector3       point  = player.Surroundings.ClosestObjectInRangeHitInfo.point;
                //Weapon weapon = null;
                if (worlditem.Is <Weapon>(out mWeapon))
                {
                    damage = mWeapon.GetDamagePackage(point, mThingToHit);
                }
                else
                {
                    damage                = new DamagePackage();
                    damage.Point          = point;
                    damage.SenderName     = worlditem.Props.Name.DisplayName;
                    damage.SenderMaterial = worlditem.Props.Global.MaterialType;
                    damage.DamageSent     = 1.0f;                                                       //absolute minimum
                    damage.ForceSent      = 1.0f;                                                       //absolute minimum
                    damage.Target         = mThingToHit;
                }
                damage.Source = Player.Local;
                DamageManager.Get.SendDamage(damage, mBodyPartToHit);

                if (damage.HitTarget)
                {
                    //Equippable equippable = null;
                    if (worlditem.Is <Equippable>(out mEquippable))
                    {
                        mEquippable.UseSuccessfully();
                    }
                }

                OnFinishUsing();
                return(true);
            }
            else
            {
                //Equippable equippable = null;
                if (worlditem.Is <Equippable>(out mEquippable))
                {
                    mEquippable.UseFinish();
                }
            }
            return(false);
        }