예제 #1
0
        /// <summary>
        /// Damages the NPC
        /// </summary>
        /// <param name="Damage">Damage to calculate</param>
        /// <param name="knockBack">Knockback amount</param>
        /// <param name="hitDirection">Direction of strike</param>
        /// <param name="crit">If the hit was critical</param>
        /// <returns>Amount of damage actually done</returns>
        public double StrikeNPC(int Damage, float knockBack, int hitDirection, bool crit = false)
        {
            if (!this.Active || this.life <= 0)
            {
                return 0.0;
            }
            double num = Main.CalculateDamage(Damage, this.defense);
            if (crit) num *= 2.0;

            if (num >= 1.0)
            {
                this.justHit = true;
                if (this.townNPC)
                {
                    this.ai[0] = 1f;
                    this.ai[1] = (float)(300 + Main.rand.Next(300));
                    this.ai[2] = 0f;
                    this.direction = hitDirection;
                    this.netUpdate = true;
                }
                if (this.aiStyle == 8)
                {
                    this.ai[0] = 400f;
                    this.TargetClosest(true);
                }
                this.life -= (int)num;
                if (knockBack > 0f && this.knockBackResist > 0f)
                {
                    float num2 = knockBack * this.knockBackResist;
                    if (crit)
                    {
                        num2 *= 1.4f;
                    }
                    if (num * 10.0 < (double)this.lifeMax)
                    {
                        if (hitDirection < 0 && this.Velocity.X > -num2)
                        {
                            if (this.Velocity.X > 0f)
                            {
                                this.Velocity.X = this.Velocity.X - num2;
                            }
                            this.Velocity.X = this.Velocity.X - num2;
                            if (this.Velocity.X < -num2)
                            {
                                this.Velocity.X = -num2;
                            }
                        }
                        else
                        {
                            if (hitDirection > 0 && this.Velocity.X < num2)
                            {
                                if (this.Velocity.X < 0f)
                                {
                                    this.Velocity.X = this.Velocity.X + num2;
                                }
                                this.Velocity.X = this.Velocity.X + num2;
                                if (this.Velocity.X > num2)
                                {
                                    this.Velocity.X = num2;
                                }
                            }
                        }
                        if (!this.noGravity)
                        {
                            num2 *= -0.75f;
                        }
                        else
                        {
                            num2 *= -0.5f;
                        }
                        if (this.Velocity.Y > num2)
                        {
                            this.Velocity.Y = this.Velocity.Y + num2;
                            if (this.Velocity.Y < num2)
                            {
                                this.Velocity.Y = num2;
                            }
                        }
                    }
                    else
                    {
                        if (!this.noGravity)
                        {
                            this.Velocity.Y = -num2 * 0.75f * this.knockBackResist;
                        }
                        else
                        {
                            this.Velocity.Y = -num2 * 0.5f * this.knockBackResist;
                        }
                        this.Velocity.X = num2 * (float)hitDirection * this.knockBackResist;
                    }
                }
                this.HitEffect(hitDirection, num);

                if (this.life <= 0)
                {
                    NPC.noSpawnCycle = true;
                    if (this.townNPC && this.type != NPCType.N37_OLD_MAN)
                    {
                        NetMessage.SendData(25, -1, -1, this.Name + " was slain...", 255, 255f, 25f, 25f);
                    }
                    if (this.townNPC && this.homeless && WorldModify.spawnNPC == this.Type)
                    {
                        WorldModify.spawnNPC = 0;
                    }

                    NPCDeathEvent Event = new NPCDeathEvent();
                    Event.Npc = this;
                    Event.Damage = Damage;
                    Event.KnockBack = knockBack;
                    Event.HitDirection = hitDirection;
                    Program.server.PluginManager.processHook(Plugin.Hooks.NPC_DEATH, Event);
                    if (Event.Cancelled)
                    {
                        return 0.0;
                    }

                    this.NPCLoot();
                    this.Active = false;
                    if (this.type == NPCType.N26_GOBLIN_PEON || this.type == NPCType.N27_GOBLIN_THIEF || this.type == NPCType.N28_GOBLIN_WARRIOR || this.type == NPCType.N29_GOBLIN_SORCERER)
                    {
                        Main.invasionSize--;
                    }
                }
                return num;
            }
            return 0.0;
        }
 /// <summary>
 /// Hook method for NPC deaths
 /// </summary>
 /// <param name="Event">NPCDeathEvent info</param>
 public virtual void onNPCDeath(NPCDeathEvent Event)
 {
 }
        public override void onNPCDeath(NPCDeathEvent Event)
        {
            //base.onNPCDeath(Event);

            //Player test = (Player)Event.Sender;

            //test.sendMessage(Event.Npc.Name);

            Player player = Main.players[Event.Npc.target];

            int xp = combatXP.getPlayerValue(player.Name);
            xp++;

            combatXP.setPlayerValue(player.Name, xp);
            combatXP.Save();

            player.sendMessage("+1 Combat XP");

            //Program.tConsole.WriteLine("NPCDeath: " + Event.Npc.Name);
            Event.Cancelled = true;
        }
        public double StrikeNPC(int Damage, float knockBack, int hitDirection)
        {
            if (!this.Active || this.life <= 0)
            {
                return 0.0;
            }
            double num = Main.CalculateDamage(Damage, this.defense);

            if (num >= 1.0)
            {
                if (this.townNPC)
                {
                    this.ai[0] = 1f;
                    this.ai[1] = (float)(300 + Main.rand.Next(300));
                    this.ai[2] = 0f;
                    this.direction = hitDirection;
                    this.netUpdate = true;
                }
                if (this.aiStyle == 8)
                {
                    this.ai[0] = 400f;
                    this.TargetClosest(true);
                }
                this.life -= (int)num;
                if (knockBack > 0f && this.knockBackResist > 0f)
                {
                    if (!this.noGravity)
                    {
                        this.Velocity.Y = -knockBack * 0.75f * this.knockBackResist;
                    }
                    else
                    {
                        this.Velocity.Y = -knockBack * 0.5f * this.knockBackResist;
                    }
                    this.Velocity.X = knockBack * (float)hitDirection * this.knockBackResist;
                }
                this.HitEffect(hitDirection, num);

                if (this.life <= 0)
                {
                    NPC.noSpawnCycle = true;
                    if (this.townNPC && this.Type != 37)
                    {
                        NetMessage.SendData(25, -1, -1, this.Name + " was slain...", 255, 255f, 25f, 25f);
                    }
                    if (this.townNPC && this.homeless && WorldGen.spawnNPC == this.Type)
                    {
                        WorldGen.spawnNPC = 0;
                    }

                    NPCDeathEvent Event = new NPCDeathEvent();
                    Event.Npc = this;
                    Event.Damage = Damage;
                    Event.KnockBack = knockBack;
                    Event.HitDirection = hitDirection;
                    Program.server.PluginManager.processHook(Plugin.Hooks.NPC_DEATH, Event);
                    if (Event.Cancelled)
                    {
                        return 0.0;
                    }

                    this.NPCLoot();
                    this.Active = false;
                    if (this.Type == 26 || this.Type == 27 || this.Type == 28 || this.Type == 29)
                    {
                        Main.invasionSize--;
                    }
                }
                return num;
            }
            return 0.0;
        }