Example #1
0
        // Do shoot
        public void ShootAtTarget(AngryGuardJobInstance instance, ref NPCBase.NPCState state)
        {
            if (!instance.Owner.Stockpile.TryRemove(this.ShootItem))
            {
                state.SetIndicator(new IndicatorState(this.CooldownMissingItem, this.ShootItem[0].Type, true, false), true);
                return;
            }

            if (this.OnShootAudio != null)
            {
                AudioManager.SendAudio(instance.eyePosition, this.OnShootAudio);
            }
            if (this.OnHitAudio != null)
            {
                AudioManager.SendAudio(instance.target.Position, this.OnHitAudio);
            }
            Vector3 positionToAimFor = instance.target.Position;

            positionToAimFor[1] += 1;
            Vector3 normalized = Vector3.Normalize(positionToAimFor - instance.eyePosition);

            ServerManager.SendParticleTrail(instance.eyePosition + normalized * 0.15f, positionToAimFor - normalized * 0.15f, Pipliz.Random.NextFloat(1.5f, 2.5f));

            Players.TakeHit(instance.target, (float)this.Damage, instance.NPC, ModLoader.OnHitData.EHitSourceType.NPC);
            state.SetIndicator(new IndicatorState(this.CooldownShot, this.ShootItem[0].Type, false, true), true);
            if (this.OnShootResultItem.item.Type > 0 && Pipliz.Random.NextDouble(0.0, 1.0) <= this.OnShootResultItem.chance)
            {
                instance.Owner.Stockpile.Add(this.OnShootResultItem.item);
            }
        }
Example #2
0
        // perform guard duty
        public void OnNPCAtJob(BlockJobInstance blockInstance, ref NPCBase.NPCState state)
        {
            AngryGuardJobInstance instance = (AngryGuardJobInstance)blockInstance;

            instance.target = PlayerTracker.FindTarget(instance.Owner, instance.eyePosition, this.Range);

            if (instance.target != null)
            {
                Vector3 positionToAimFor = instance.target.Position;
                positionToAimFor[1] += 1;
                instance.NPC.LookAt(positionToAimFor);
                this.ShootAtTarget(instance, ref state);
            }
            else
            {
                state.SetCooldown((double)this.CooldownSearchingTarget);
                Vector3 val = instance.Position.Vector;
                int     num;
                if (this.BlockTypes.ContainsByReference <ItemTypes.ItemType>(instance.BlockType, out num))
                {
                    switch (num)
                    {
                    case 1:
                        val += Vector3.right;
                        break;

                    case 2:
                        val += Vector3.left;
                        break;

                    case 3:
                        val += Vector3.forward;
                        break;

                    case 4:
                        val += Vector3.back;
                        break;
                    }
                    instance.NPC.LookAt(val);
                }
            }
            return;
        }