コード例 #1
0
ファイル: BowItem.cs プロジェクト: mattbalmer/eco-server
        public void Hit(NetObjAttachInfo hitAttachInfo, Vector3 position, string location)
        {
            if (!(this.Controller is Player player))
            {
                return;
            }

            var target = NetObjectManager.GetObject <INetObject>(hitAttachInfo.ParentID);

            switch (target)
            {
            // bow only damages animals // Auth will be checked inside TryApplyDamage via HarvestOrHunt. Other cases are harmless.
            case AnimalEntity targetAnimal:
            {
                targetAnimal.AttachedEntities.Add(this);

                var hitHead = location.Contains("Head");
                // player will get x2.5 exp when hit head
                var experienceMultiplier = hitHead ? 2.5f : 1f;
                // player will do x2 damage when hit head and x2 again if they have HuntingDeadeyeTalent
                var locationMultiplier = hitHead ? player.User.Talentset.HasTalent(typeof(HuntingDeadeyeTalent)) ? 4 : 2 : 1;
                var interactionContext = new InteractionContext()
                {
                    SelectedStack = new ItemStack(this.BowItem, 1)
                };
                if (targetAnimal.Dead || targetAnimal.TryApplyDamage(player, this.Damage * locationMultiplier, interactionContext, this.BowItem, typeof(ArrowItem), experienceMultiplier))
                {
                    this.Attached = hitAttachInfo;
                }
                else
                {
                    this.Destroy();
                }
                break;
            }

            case Player targetPlayer:
                // arrows look silly sticking in player capsule colliders
                player.ErrorLoc($"You must obtain authorization to shoot {targetPlayer.User.MarkedUpName}.");
                this.Destroy();
                break;

            default:
                this.Attached = hitAttachInfo;
                break;
            }

            Animal.AlertNearbyAnimals(this.Position, 15f);

            if (this.Attached != null)
            {
                this.RPC("Attach", this.Attached);
            }

            this.Position = position;
            this.Rotation = Quaternion.LookRotation(this.Velocity.Normalized);
            this.Velocity = Vector3.Zero;
        }
コード例 #2
0
    public void Hit(NetObjAttachInfo hitAttachInfo, Vector3 position, string location)
    {
        var other = NetObjectManager.GetObject <INetObject>(hitAttachInfo.ParentID);

        if (this.Controller is Player && AuthManager.IsAuthorized(position.Round, (this.Controller as Player).User).Notify(this.Controller as Player))
        {
            // bow only damages animals
            var animal = other as AnimalEntity;
            if (animal != null)
            {
                animal.AttachedEntities.Add(this);
                Player player = this.Controller as Player;
                if (player != null)
                {
                    var locationMultiplier = location.Contains("Head") ? (player.User.Talentset.HasTalent(typeof(HuntingDeadeyeTalent)) ? 4 : 2) : 1;
                    if (animal.Dead || animal.TryApplyDamage(player, BowItem.Damage.GetCurrentValue(player.User) * locationMultiplier, new InteractionContext()
                    {
                        SelectedItem = Item.Get(typeof(BowItem))
                    }, typeof(ArrowItem)))
                    {
                        this.attached = hitAttachInfo;
                    }
                    else
                    {
                        this.Destroy();
                    }
                }
            }
            else if (other is Player)
            {
                // arrows look silly sticking in player capsule colliders
                LocString s = Localizer.Format("You must obtain authorization to shoot {0}.", (other as Player).DisplayName);
                (this.Controller as Player).SendTemporaryError(s);
                this.Destroy();
            }
            else
            {
                this.attached = hitAttachInfo;
            }
        }

        Animal.AlertNearbyAnimals(this.Position, 10f);

        if (this.attached != null)
        {
            this.RPC("Attach", this.attached);
        }

        this.Position = position;
        this.Rotation = Quaternion.LookRotation(this.Velocity.Normalized);
        this.Velocity = Vector3.Zero;
    }
コード例 #3
0
    public void Hit(NetObjAttachInfo hitAttachInfo, Vector3 position)
    {
        var other = NetObjectManager.GetObject <INetObject>(hitAttachInfo.ParentID);

        if (this.Controller is Player && AuthManager.IsAuthorized(position.Round, (this.Controller as Player).User).Notify(this.Controller as Player))
        {
            // bow only damages animals
            var animal = other as AnimalEntity;
            if (animal != null)
            {
                Player player = this.Controller as Player;
                if (player != null)
                {
                    if (animal.TryApplyDamage(player, BowItem.Damage.GetCurrentValue(player.User), null))
                    {
                        this.attached = hitAttachInfo;
                    }
                    else
                    {
                        this.Destroy();
                    }
                }
            }
            else if (other is Player)
            {
                // arrows look silly sticking in player capsule colliders
                var s = FormattableStringFactory.Create("You must obtain authorization to shoot {0}.", (other as Player).DisplayName);
                (this.Controller as Player).SendTemporaryError(s);
                this.Destroy();
            }
            else
            {
                this.attached = hitAttachInfo;
            }
        }

        if (this.attached != null)
        {
            this.RPC("Attach", this.attached);
        }

        this.Position = position;
        this.Rotation = Quaternion.LookRotation(this.Velocity.Normalized);
        this.Velocity = Vector3.Zero;
    }