public override void OnHitNPC(Player player, NPC target, int damage, float knockback, bool crit)
 {
     if(Main.rand.Next(2) == 0)
     {
         target.AddBuff(BuffID.OnFire, 500);
     }
 }
示例#2
0
 public override void OnHitNPC(NPC target, int damage, float knockback, bool crit)
 {
     if (Main.rand.Next(8) == 0)
     {
         target.AddBuff(BuffID.Confused, 240, true);
     }
 }
示例#3
0
 //in Terraria.Projectile.Damage for damaging NPCs before flag2 is checked... just check the patch files
 internal static bool? CanHitNPC(Projectile projectile, NPC target)
 {
     bool? flag = null;
     foreach (GlobalProjectile globalProjectile in globalProjectiles)
     {
         bool? canHit = globalProjectile.CanHitNPC(projectile, target);
         if (canHit.HasValue && !canHit.Value)
         {
             return false;
         }
         if (canHit.HasValue)
         {
             flag = canHit.Value;
         }
     }
     if (IsModProjectile(projectile))
     {
         bool? canHit = projectile.modProjectile.CanHitNPC(target);
         if (canHit.HasValue && !canHit.Value)
         {
             return false;
         }
         if (canHit.HasValue)
         {
             flag = canHit.Value;
         }
     }
     return flag;
 }
示例#4
0
		public override void OnHitNPC(NPC target, int damage, float knockback, bool crit)
		{
			if (Main.rand.Next(2) == 0)
			{
				target.AddBuff(mod.BuffType("EtherealFlames"), 300);
			}
		}
示例#5
0
        public override void OnHitNPC(NPC target, int damage, float knockback, bool crit)
        {
            if (Main.rand.Next(10) == 0) // 10% chance to inflict slow on an enemy.
                target.AddBuff(BuffID.Slow, 5);

            base.OnHitNPC(target, damage, knockback, crit);
        }
示例#6
0
 public override void NPCLoot(NPC npc)
 {
     if (npc.type == NPCID.Plantera)
     {
         Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("ThornbloomKnife"), Main.rand.Next(40, 60));
     }
 }
示例#7
0
        /// <summary>
        /// Occurs when the server has received a message from the client.
        /// </summary>
        protected void NetHooks_GetData(GetDataEventArgs args)
        {
            byte[]          bufferSegment = null;
            Terraria.Player player        = null;

            if ((player = Terraria.Main.player.ElementAtOrDefault(args.Msg.whoAmI)) == null)
            {
                return;
            }

            bufferSegment = new byte[args.Length];
            System.Array.Copy(args.Msg.readBuffer, args.Index, bufferSegment, 0, args.Length);

            if (args.MsgID == PacketTypes.NpcStrike)
            {
                Terraria.NPC      npc       = null;
                Packets.DamageNPC dmgPacket = Packets.PacketMarshal.MarshalFromBuffer <Packets.DamageNPC>(bufferSegment);

                if (dmgPacket.NPCID < 0 || dmgPacket.NPCID > Terraria.Main.npc.Length ||
                    args.Msg.whoAmI < 0 || dmgPacket.NPCID > Terraria.Main.player.Length)
                {
                    return;
                }

                if ((npc = Terraria.Main.npc.ElementAtOrDefault(dmgPacket.NPCID)) == null)
                {
                    return;
                }

                AddNPCDamage(npc, player, dmgPacket.Damage, Convert.ToBoolean(dmgPacket.CrititcalHit));
            }
        }
 public override void OnHitNPC(NPC target, int damage, float knockback, bool crit)
 {
     if (Main.rand.Next(0) == 0)
     {
         target.AddBuff(mod.BuffType("ElectrifiedV2"), 540, true);
     }
 }
示例#9
0
        private void dropBiomeParts(Terraria.NPC npc)
        {
            Config     c     = ModContent.GetInstance <Config>();
            Player     p     = ARareItemSwapJPANs.findNearestPlayer(npc.Center);
            List <int> parts = new List <int>();

            foreach (ModPartRepository mpr in modpacks)
            {
                foreach (int i in mpr.getBiomePartsDrops(npc, p, parts))
                {
                    if (!parts.Contains(i))
                    {
                        parts.Add(i);
                    }
                }
            }
            if (Main.rand.NextDouble() < c.partDropChance)
            {
                for (int i = 0; i < c.maxDifferentParts && parts.Count > 0; i++)
                {
                    int idx  = Main.rand.Next(parts.Count);
                    int prts = c.minParts + Main.rand.Next(c.randParts + 1);
                    Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, parts[idx], prts, false, 0, false, false);
                    parts.RemoveAt(idx);
                }
            }
        }
示例#10
0
 public override void NPCLoot(NPC npc)
 {
     if (Main.player[Main.myPlayer].ZoneSnow && Main.rand.Next(5) == 3)
     {
         Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("IceEssense"), 1);
     }
 }
示例#11
0
 //in Terraria.NPC.DropBossBags after if statements setting bag type call
 //  NPCLoader.BossBag(this, ref num);
 internal static void BossBag(NPC npc, ref int bagType)
 {
     if (IsModNPC(npc))
     {
         bagType = npc.modNPC.bossBag;
     }
 }
示例#12
0
 public override void NPCLoot(NPC npc)
 {
     if (npc.lifeMax > 5 && npc.value > 0f)
     {
         Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("ExampleItem"));
     }
 }
示例#13
0
        /// <summary>
        /// Should occur when an NPC dies; gives rewards out to all the players that hit it.
        /// </summary>
        protected void ProcessNPCDeath(Terraria.NPC NPC)
        {
            List <PlayerDamage>         playerDamageList = null;
            Dictionary <Player, double> argsDict;
            NPCDeathEventArgs           args;

            lock (__dictionaryMutex) {
                if (DamageDictionary.ContainsKey(NPC))
                {
                    playerDamageList = DamageDictionary[NPC];

                    if (DamageDictionary.Remove(NPC) == false)
                    {
                        TShock.Log.ConsoleError("seconomy: world economy: Remove of NPC after reward failed.  This is an internal error.");
                    }
                }
            }

            if (playerDamageList == null ||
                NPCDeath == null)
            {
                return;
            }

            argsDict = new Dictionary <Player, double>();
            args     = new NPCDeathEventArgs(NPC, argsDict);

            foreach (PlayerDamage dmg in playerDamageList)
            {
                argsDict.Add(dmg.Player, dmg.Damage);
            }

            NPCDeath(this, args);
        }
 public override void OnHitNPC(NPC target, int damage, float knockback, bool crit)
 {
     if (Main.rand.Next(25) == 0)
     {
         target.AddBuff(BuffID.BrokenArmor, 200, true);
     }
 }
示例#15
0
		public override void OnHitNPC(NPC target, int damage, float knockback, bool crit)
		{
			if (Main.rand.Next(10) == 0)
			{
				target.AddBuff(BuffID.OnFire, 180, false);
			}
		}
示例#16
0
        public override void OnHitNPC(Terraria.NPC target, int damage, float knockback, bool crit)
        {
            hitNPC = true;

            if (projectile.Center.X > target.Center.X)
            {
                bounceX = 8;
            }
            else
            {
                bounceX = -8;
            }

            if (projectile.Center.Y > target.Center.Y)
            {
                bounceY = 8;
            }
            else
            {
                bounceY = -8;
            }

            if (hitNPC)
            {
                bounceCount++;
                Main.PlaySound(SoundID.Item21, projectile.position);
                Projectile.NewProjectile(projectile.Center.X + bounceX, projectile.Center.Y + bounceY, (projectile.velocity.X *= -1) / 2, (projectile.velocity.Y *= -1) / 2, mod.ProjectileType("Nousagi"), 60 + (20 * bounceCount), 10 + (10 * bounceCount), Terraria.Main.myPlayer, 0f, 0f);
            }
        }
示例#17
0
        public override void ModifyHitNPC(Player player, NPC target, ref int damage, ref float knockBack, ref bool crit)
        {
            Vector2 loc = player.itemLocation;
            loc.Y -= 20;

            Random rand = new Random();
            int r = rand.Next(0, 6);

            if (r == 0)
            {
                for (int i = 0; i < 9; i++)
                {
                    Dust.NewDust(loc, 50, 30, mod.DustType("Garnsworddust"), 0.0F, 0.0F, 0, default(Color), 4.5F);
                }

                damage += (int) (damage * 0.4);

                int healamount = (int)(damage * 0.33);
                player.HealEffect(healamount, true);

                if (player.statLife + healamount <= (player.statLifeMax + player.statLifeMax2))
                {
                    player.statLife += healamount;
                }
                else
                {
                    player.statLife = (player.statLifeMax + player.statLifeMax2);
                }
            }
        }
 public override void OnHitNPC(NPC target, int damage, float knockback, bool crit)
 {
     if (Main.rand.Next(2) == 0)
     {
         target.AddBuff(BuffID.CursedInferno, 60, false);
     }
 }
示例#19
0
 public static bool OnStrikeNpc(NPC npc, ref int damage, ref float knockback, ref int hitdirection, ref bool crit, ref bool noEffect, ref double retdamage)
 {
     if (NpcHooks.StrikeNpc == null)
     {
         return false;
     }
     NpcStrikeEventArgs npcStrikeEventArgs = new NpcStrikeEventArgs
     {
         Npc = npc,
         Damage = damage,
         KnockBack = knockback,
         HitDirection = hitdirection,
         Critical = crit,
         NoEffect = noEffect,
         ReturnDamage = retdamage
     };
     NpcHooks.StrikeNpc(npcStrikeEventArgs);
     crit = npcStrikeEventArgs.Critical;
     damage = npcStrikeEventArgs.Damage;
     knockback = npcStrikeEventArgs.KnockBack;
     hitdirection = npcStrikeEventArgs.HitDirection;
     noEffect = npcStrikeEventArgs.NoEffect;
     retdamage = npcStrikeEventArgs.ReturnDamage;
     return npcStrikeEventArgs.Handled;
 }
示例#20
0
 public override void OnHitNPC(Player player, NPC target, int damage, float knockBack, bool crit)
 {
     if(!target.boss)
     {
     target.velocity.Y -= 5;
     }
 }
 public override void OnHitNPC(Player player, NPC target, int damage, float knockback, bool crit)
 {
     target.AddBuff(BuffID.OnFire, 10);
     target.AddBuff(BuffID.Electrified, 3);
     target.AddBuff(BuffID.Venom, 5);
     target.AddBuff(BuffID.CursedInferno, 4);
 }
示例#22
0
 public virtual void OnHitByNPC(NPC npc, int damage, bool crit)
 {
     if (Main.rand.Next(4) == 0)
     {
         npc.AddBuff(BuffID.ShadowFlame, 200, true);
     }
 }
示例#23
0
        public override void OnHitByNPC(Terraria.NPC npc, int damage, bool crit)
        {
            Terraria.Player player = Terraria.Main.player[npc.target];
            if (PoweredBattery)
            {
                if (Terraria.Main.rand.NextBool(10))
                {
                    Terraria.Projectile.NewProjectile(player.Center.X, player.Center.Y, 0f, 0f, ModContent.ProjectileType <EnergyAura>(), 3, 2, player.whoAmI);
                }
            }
            if (PhanticMeleeBonus)
            {
                if (damage > 10)
                {
                    Vector2 offset = new Vector2(0, -100);
                    Terraria.Projectile.NewProjectile(player.Center + offset, new Vector2(0 + ((float)Terraria.Main.rand.Next(20) / 10) - 1, -3 + ((float)Terraria.Main.rand.Next(20) / 10) - 1), ModContent.ProjectileType <PhanticSoul>(), 6, 1f, Terraria.Main.myPlayer);
                }
            }
            if (BurnshockArmorBonus)
            {
                if (damage > 25)
                {
                    Vector2 offset = new Vector2(0, -100);

                    Terraria.Projectile.NewProjectile(player.Center + offset, new Vector2(0 + ((float)Terraria.Main.rand.Next(20) / 10) - 1, -3 + ((float)Terraria.Main.rand.Next(20) / 10) - 1), ModContent.ProjectileType <BurnshockCrystal>(), 40, 1f, Terraria.Main.myPlayer);
                    Terraria.Projectile.NewProjectile(player.Center + offset, new Vector2(0 + ((float)Terraria.Main.rand.Next(20) / 10) - 1, -3 + ((float)Terraria.Main.rand.Next(20) / 10) - 1), ModContent.ProjectileType <BurnshockCrystal>(), 40, 1f, Terraria.Main.myPlayer);
                    Terraria.Projectile.NewProjectile(player.Center + offset, new Vector2(0 + ((float)Terraria.Main.rand.Next(20) / 10) - 1, -3 + ((float)Terraria.Main.rand.Next(20) / 10) - 1), ModContent.ProjectileType <BurnshockCrystal>(), 40, 1f, Terraria.Main.myPlayer);
                }
            }
        }
示例#24
0
 //in Terraria.Player.ItemCheck before checking whether npc type can be hit add
 //  bool? modCanHit = ItemLoader.CanHitNPC(item, this, Main.npc[num292]);
 //  if(modCanHit.HasValue && !modCanHit.Value) { continue; }
 //in if statement afterwards add || (modCanHit.HasValue && modCanHit.Value)
 internal static bool? CanHitNPC(Item item, Player player, NPC target)
 {
     bool? flag = null;
     foreach (GlobalItem globalItem in globalItems)
     {
         bool? canHit = globalItem.CanHitNPC(item, player, target);
         if (canHit.HasValue && !canHit.Value)
         {
             return false;
         }
         if (canHit.HasValue)
         {
             flag = canHit.Value;
         }
     }
     if (IsModItem(item))
     {
         bool? canHit = item.modItem.CanHitNPC(player, target);
         if (canHit.HasValue && !canHit.Value)
         {
             return false;
         }
         if (canHit.HasValue)
         {
             flag = canHit.Value;
         }
     }
     return flag;
 }
        /// <summary>
        /// When an <see cref="NPC" /> is damaged by the <see cref="Projectile" />.
        /// </summary>
        /// <param name="n">The <see cref="NPC" /> that got damaged.</param>
        /// <param name="dir">In which direction the <see cref="NPC"/> got hit.</param>
        /// <param name="dmg">The damage dealt to the <see cref="NPC" />.</param>
        /// <param name="kb">The knockback the <see cref="NPC" /> wil receive.</param>
        /// <param name="crit">Wether it was a critical hit or not.</param>
        /// <param name="cMult">The damage multiplier of a critical hit.</param>
        public override void DamageNPC(NPC n, int dir, ref int dmg, ref float kb, ref bool crit, ref float cMult)
        {
            base.DamageNPC(n, dir, ref dmg, ref kb, ref crit, ref cMult);

            if (Main.rand.Next(3) == 0)
                n.AddBuff(20, 300);
        }
示例#26
0
 public override void OnHitByNPC(NPC npc, int damage, bool crit)
 {
     if (this.basiliskMount)
     {
         int num = player.statDefense / 2;
         npc.StrikeNPCNoInteraction(num, 0f, 0, false, false, false);
     }
 }
示例#27
0
		internal void SetupNPC(NPC npc)
		{
			ModNPC newNPC = (ModNPC)Activator.CreateInstance(GetType());
			newNPC.npc = npc;
			npc.modNPC = newNPC;
			newNPC.mod = mod;
			newNPC.SetDefaults();
		}
示例#28
0
 public static void ChooseNPC()
 {
     var npc = new NPC();
     Random r = new Random();
     int type = r.Next(ApocalypseMonsters.Monsters.Count);
     npc.SetDefaults(ApocalypseMonsters.Monsters[type]);
     CurMonster = npc;
 }
示例#29
0
 public override void OnHitNPC(Player player, NPC target, int damage, float knockback, bool crit)
 {
     target.AddBuff(BuffID.CursedInferno, 3);
     target.AddBuff(BuffID.Frostburn, 2);
     target.AddBuff(BuffID.Frozen, 1);
     target.AddBuff(BuffID.Chilled, 20);
     target.AddBuff(BuffID.OnFire, 10);
 }
示例#30
0
		internal void SetupNPC(NPC npc)
		{
			ModNPC newNPC = (ModNPC)(CloneNewInstances ? MemberwiseClone() : Activator.CreateInstance(GetType()));
			newNPC.npc = npc;
			npc.modNPC = newNPC;
			newNPC.mod = mod;
			newNPC.SetDefaults();
		}
 public override void OnHitNPC(NPC target, int damage, float knockback, bool crit)
 {
     if (Main.rand.Next(8) == 0)
     {
         target.AddBuff(BuffID.CursedInferno, 200, true);
         target.AddBuff(BuffID.OnFire, 200, true);
         target.AddBuff(BuffID.Frostburn, 200, true);
     }
 }
示例#32
0
        internal static void OnFindFrame(NPC n)
        {
            n.RealFindFrame();

            var bh = n.P_BHandler as NpcBHandler;

            if (bh != null)
                bh.FindFrame();
        }
        public override void OnHitNPC(Terraria.Player player, Terraria.NPC target, int damage, float knockBack, bool crit)
        {
            int chance = 60 / UseSpeedArray[0];

            if (Terraria.Main.rand.NextBool(chance * 3))
            {
                target.AddBuff(Terraria.ID.BuffID.OnFire, 60 * (chance));
            }
        }
示例#34
0
 public override void SetDefaults(NPC npc)
 {
     if (npc.type == 379)
     {
         npc.townNPC = true;
         npc.lifeMax = 5000;
         npc.knockBackResist = 0f;
     }
 }
示例#35
0
 public static void SetPosition(NPC npc)
 {
     CaptiveElement modNPC = npc.modNPC as CaptiveElement;
     if (modNPC != null)
     {
         Vector2 center = Main.npc[modNPC.center].Center;
         double angle = Main.npc[modNPC.center].ai[3] + 2.0 * Math.PI * modNPC.captiveType / 5.0;
         npc.position = center + 300f * (new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle))) - npc.Size / 2f;
     }
 }
示例#36
0
 public override void OnHitNPC(Terraria.Item item, Terraria.NPC target, int damage, float knockback, bool crit)
 {
     if (FrostMelee)
     {
         if (Terraria.Main.rand.NextBool(2))
         {
             target.AddBuff(BuffID.Frostburn, 120);
         }
     }
 }
示例#37
0
 public void OnHitNPC(Player p, NPC target, int damage, float knockBack, bool crit)
 {
     if (Main.rand.Next(4) == 1)
     {
         Vector2 velocity = new Vector2(p.direction, 0) * 4f;
         int proj = Terraria.Projectile.NewProjectile(p.Center.X, p.position.Y + p.height + -35, velocity.X, velocity.Y, mod.ProjectileType("TimeWinderClone"), damage = 60, projectile.owner, 0, 0f);
         Main.projectile[proj].friendly = true;
         Main.projectile[proj].hostile = false;
     }
 }
示例#38
0
 public override void NPCLoot(Terraria.NPC npc)
 {
     base.NPCLoot(npc);
     dropBossParts(npc);
     if (npc.value > 1)
     {
         dropSeasonalParts(npc);
         dropWeatherParts(npc);
         dropEventParts(npc);
         dropBiomeParts(npc);
         dropStageParts(npc);
         dropShopParts(npc);
     }
 }
示例#39
0
        public override void OnHitNPCWithProj(Terraria.Projectile proj, Terraria.NPC target, int damage, float knockback, bool crit)
        {
            if (QueensStinger)
            {
                if (proj.type != 181)
                {
                    if (Terraria.Main.rand.NextBool(10))
                    {
                        Terraria.Projectile.NewProjectile(target.Center.X, target.Center.Y, 0f, 0f, ProjectileID.Bee, 3, 2, player.whoAmI);
                    }
                }
            }

            if (EmeraldEmpoweredGem)
            {
                target.AddBuff(39, 40);
            }

            if (MidasCrown)
            {
                target.AddBuff(BuffID.Midas, 900);
            }

            if (FrostProjectile)
            {
                if (Terraria.Main.rand.NextBool(2))
                {
                    target.AddBuff(BuffID.Frostburn, 120);
                }
            }


            if (SpiritCultistBonus && proj.magic && !target.boss)
            {
                if (target.FindBuffIndex(ModContent.BuffType <LiftedSpiritsDebuff>()) < 1)
                {
                    target.velocity.Y -= 20;
                }

                target.AddBuff(ModContent.BuffType <LiftedSpiritsDebuff>(), 210);
            }
            if (PhanticRangedBonus && proj.ranged && Terraria.Main.rand.NextFloat() < 0.15f && proj.type != ModContent.ProjectileType <PhanticSoul>())
            {
                float   rot      = Terraria.Main.rand.NextFloat(MathHelper.TwoPi);
                Vector2 position = target.Center + Vector2.One.RotatedBy(rot) * 180;
                Vector2 velocity = Vector2.One.RotatedBy(rot) * -1 * 12f;
                Terraria.Projectile.NewProjectile(position, velocity, ModContent.ProjectileType <PhanticSoul>(), 30, player.HeldItem.knockBack, player.whoAmI, 0, 0);
            }
        }
示例#40
0
        public static int GetNearestAlivePlayer(Terraria.NPC npc)
        {
            float NearestPlayerDist = 4815162342f;
            int   NearestPlayer     = -1;

            foreach (Player player in Main.player)
            {
                if (player.Distance(npc.Center) < NearestPlayerDist && player.active)
                {
                    NearestPlayerDist = player.Distance(npc.Center);
                    NearestPlayer     = player.whoAmI;
                }
            }
            return(NearestPlayer);
        }
示例#41
0
        private void dropSeasonalParts(Terraria.NPC npc)
        {
            Config c = ModContent.GetInstance <Config>();

            if (Main.halloween && Main.rand.NextDouble() < c.partDropChance)
            {
                int parts = c.minParts + Main.rand.Next(c.randParts + 1);
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, ModContent.ItemType <GoodieBagPart>(), parts, false, 0, false, false);
            }
            if (Main.xMas && Main.rand.NextDouble() < c.partDropChance)
            {
                int parts = c.minParts + Main.rand.Next(c.randParts + 1);
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, ModContent.ItemType <PresentPart>(), parts, false, 0, false, false);
            }
        }
示例#42
0
        /// <summary>
        /// Adds damage done by a player to an NPC slot.  When the NPC dies the rewards for it will fill out.
        /// </summary>
        protected void AddNPCDamage(Terraria.NPC NPC, Terraria.Player Player, int Damage, bool crit = false)
        {
            List <PlayerDamage> damageList   = null;
            PlayerDamage        playerDamage = null;
            double dmg;


            if (Player == null || NPC.active == false || NPC.life <= 0)
            {
                return;
            }

            lock (__dictionaryMutex)
            {
                if (DamageDictionary.ContainsKey(NPC))
                {
                    damageList = DamageDictionary[NPC];
                }
                else
                {
                    damageList = new List <PlayerDamage>(1);
                    DamageDictionary.Add(NPC, damageList);
                }
            }

            lock (__NPCDamageMutex)
            {
                if ((playerDamage = damageList.FirstOrDefault(i => i.Player == Player)) == null)
                {
                    playerDamage = new PlayerDamage()
                    {
                        Player = Player
                    };
                    damageList.Add(playerDamage);
                }

                if ((dmg = (crit ? 2 : 1) * Main.CalculateDamage(Damage, NPC.ichor ? NPC.defense - 20 : NPC.defense)) > NPC.life)
                {
                    dmg = NPC.life;
                }
            }
            playerDamage.Damage += dmg;

            if (playerDamage.Damage > NPC.lifeMax)
            {
                playerDamage.Damage -= playerDamage.Damage % NPC.lifeMax;
            }
        }
示例#43
0
 private void dropBossParts(Terraria.NPC npc)
 {
     if (npcParts.ContainsKey(npc.type))
     {
         foreach (Item part in npcParts[npc.type])
         {
             if (npc.boss ||
                 (npc.type != 13 && npc.type != 14 && npc.type != 15))
             {
                 Config c     = ModContent.GetInstance <Config>();
                 int    parts = c.minNumOfBossParts + Main.rand.Next(c.randNumOfBossParts + 1);
                 Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, part.type, parts, false, 0, false, false);
             }
         }
     }
 }
示例#44
0
        /// <summary>
        /// Occurs when the server has received a message from the client.
        /// </summary>
        protected void NetHooks_GetData(GetDataEventArgs args)
        {
            byte[]   bufferSegment = null;
            TSPlayer player        = null;

            if (args.Handled == true ||
                (player = TShock.Players.ElementAtOrDefault(args.Msg.whoAmI)) == null)
            {
                return;
            }

            bufferSegment = new byte[args.Length];
            System.Array.Copy(args.Msg.readBuffer, args.Index, bufferSegment, 0, args.Length);

            if (args.MsgID == PacketTypes.NpcStrike)
            {
                Terraria.NPC      npc       = null;
                Packets.DamageNPC dmgPacket = Packets.PacketMarshal.MarshalFromBuffer <Packets.DamageNPC>(bufferSegment);

                if (dmgPacket.NPCID < 0 || dmgPacket.NPCID > Terraria.Main.npc.Length ||
                    args.Msg.whoAmI < 0 || dmgPacket.NPCID > Terraria.Main.player.Length)
                {
                    return;
                }

                if ((npc = Terraria.Main.npc.ElementAtOrDefault(dmgPacket.NPCID)) == null)
                {
                    return;
                }

                if (DateTime.UtcNow.Subtract(player.LastThreat).TotalMilliseconds < 5000)
                {
                    return;
                }

                AddNPCDamage(npc, player.TPlayer, dmgPacket.Damage, Convert.ToBoolean(dmgPacket.CrititcalHit));
            }
        }
示例#45
0
        private void dropShopParts(Terraria.NPC npc)
        {
            Config c = ModContent.GetInstance <Config>();
            Player p = ARareItemSwapJPANs.findNearestPlayer(npc.Center);

            if (Main.rand.NextDouble() < c.shopPartDropChance)
            {
                if (npc.value < 500)
                {
                    int parts = Main.rand.Next(1, (int)(npc.value / 5) + 1);
                    Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, ModContent.ItemType <MinorShopPart>(), parts, false, 0, false, false);
                }
                else if (npc.value < 50000)
                {
                    int parts = Main.rand.Next(1, (int)(npc.value / 500) + 1);
                    Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, ModContent.ItemType <ShopPart>(), parts, false, 0, false, false);
                }
                else if (npc.value >= 50000)
                {
                    int parts = Main.rand.Next(1, (int)(npc.value / 50000) + 1);
                    Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, ModContent.ItemType <MajorShopPart>(), parts, false, 0, false, false);
                }
            }
        }
示例#46
0
 public override void ModifyHitNPCWithProj(Terraria.Player player, SkillData rawdata, Terraria.Projectile proj, Terraria.NPC target, ref int damage, ref float knockback, ref bool crit, ref int hitDirection)
 {
     if (proj.minion || proj.type == 376 || proj.type == 378 || proj.type == 379 || proj.type == 389 || proj.type == 408 || proj.type == 614)
     {
         SummonPotenceSkillData data = (SummonPotenceSkillData)rawdata;
         int CriticalRate            = data.Level + data.LoggedCriticalBonus;
         if (data.Level > 5)
         {
             CriticalRate += 5;
         }
         if (Terraria.Main.rand.Next(100) < CriticalRate)
         {
             //damage *= 2;
             crit = true;
         }
     }
 }
示例#47
0
        /// <summary>
        /// Should occur when an NPC dies; gives rewards out to all the players that hit it.
        /// </summary>
        protected void GiveRewardsForNPC(Terraria.NPC NPC)
        {
            List <PlayerDamage> playerDamageList = null;
            IBankAccount        account;
            TSPlayer            player;
            Money rewardMoney = 0L;

            lock (__dictionaryMutex)
            {
                if (DamageDictionary.ContainsKey(NPC))
                {
                    playerDamageList = DamageDictionary[NPC];

                    if (DamageDictionary.Remove(NPC) == false)
                    {
                        TShock.Log.ConsoleError("seconomy: world economy: Remove of NPC after reward failed.  This is an internal error.");
                    }
                }
            }

            if (playerDamageList == null)
            {
                return;
            }

            if (((NPC.boss && WorldConfiguration.MoneyFromBossEnabled) || (!NPC.boss && WorldConfiguration.MoneyFromNPCEnabled)) && !(NPC.SpawnedFromStatue && WorldConfiguration.IgnoreSpawnedFromStatue))
            {
                foreach (PlayerDamage damage in playerDamageList)
                {
                    if (damage.Player == null ||
                        (player = TShockAPI.TShock.Players.FirstOrDefault(i => i != null && i.Index == damage.Player.whoAmI)) == null ||
                        (account = Parent.GetBankAccount(player)) == null)
                    {
                        continue;
                    }

                    rewardMoney = CustomMultiplier * Convert.ToInt64(Math.Round(Convert.ToDouble(WorldConfiguration.MoneyPerDamagePoint) * damage.Damage));

                    //load override by NPC type, this allows you to put a modifier on the base for a specific mob type.
                    Configuration.WorldConfiguration.NPCRewardOverride overrideReward = WorldConfiguration.Overrides.FirstOrDefault(i => i.NPCID == NPC.type);
                    if (overrideReward != null)
                    {
                        rewardMoney = CustomMultiplier * Convert.ToInt64(Math.Round(Convert.ToDouble(overrideReward.OverridenMoneyPerDamagePoint) * damage.Damage));
                    }

                    if (rewardMoney <= 0 || player.Group.HasPermission("seconomy.world.mobgains") == false)
                    {
                        continue;
                    }

                    Journal.CachedTransaction fund = new Journal.CachedTransaction()
                    {
                        Aggregations            = 1,
                        Amount                  = rewardMoney,
                        DestinationBankAccountK = account.BankAccountK,
                        Message                 = NPC.FullName,
                        SourceBankAccountK      = Parent.WorldAccount.BankAccountK
                    };

                    if ((NPC.boss && WorldConfiguration.AnnounceBossKillGains) || (!NPC.boss && WorldConfiguration.AnnounceNPCKillGains))
                    {
                        fund.Options |= Journal.BankAccountTransferOptions.AnnounceToReceiver;
                    }

                    //commit it to the transaction cache
                    Parent.TransactionCache.AddCachedTransaction(fund);
                }
            }
        }