Пример #1
0
 public void HitStatic(Vector3 position, Quaternion rotation)
 {
     this.Position = position;
     this.Rotation = rotation;
     this.Velocity = Vector3.Zero;
     this.RPC("Attach", position, rotation);
     Animal.AlertNearbyAnimals(this.Position, 5f);
 }
Пример #2
0
        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;
        }
    void FellTree(INetObject killer)
    {
        // create the initial trunk piece
        var trunkPiece = new TrunkPiece()
        {
            ID = Guid.NewGuid(), SliceStart = 0f, SliceEnd = 1f,
        };

        // clear tree occupancy
        if (this.Species.BlockType != null)
        {
            var treeBlockCheck = this.Position.Round + Vector3i.Up;
            while (World.GetBlock(treeBlockCheck).GetType() == this.Species.BlockType)
            {
                World.DeleteBlock(treeBlockCheck);
                treeBlockCheck += Vector3i.Up;
            }
        }

        this.trunkPieces.Add(trunkPiece);

        if (killer is Player)
        {
            this.SetPhysicsController((INetObjectViewer)killer);
            killer.RPC("YellTimber");
            Animal.AlertNearbyAnimals(this.Position, 30);
        }

        this.RPC("FellTree", trunkPiece.ID, this.resourceMultiplier);

        // break off any branches that are young
        for (int branchID = 0; branchID < this.branches.Count(); branchID++)
        {
            var branch = this.branches[branchID];
            if (branch == null)
            {
                continue;
            }

            var branchAge = Mathf.Clamp01((float)((this.GrowthPercent - branch.SpawnAge) / (branch.MatureAge - branch.SpawnAge)));
            if (branchAge <= .5f)
            {
                this.DestroyBranch(branchID);
            }
        }

        if (killer is Player)
        {
            PlantSimEvents.OnTreeFelled.Invoke((killer as Player).DisplayName);
        }

        //Add air pollution (minor)
        WorldLayerManager.ClimateSim.AddAirPollution(new WorldPosition3i(this.Position.XYZi), -this.Species.ReleasesCO2ppmPerDay);

        this.Save();
    }
Пример #4
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;
    }