public override void Hurt(bool pvp, bool quiet, double damage, int hitDirection, bool crit) { if (blockyAccessory) { Main.PlaySound(SoundID.Zombie, player.position, 13); } if (elementShield && damage > 1.0) { if (elementShields < 6) { int k; bool flag = false; for (k = 3; k < 8 + player.extraAccessorySlots; k++) { if (player.armor[k].type == ItemType <SixColorShield>()) { flag = true; break; } } if (flag) { Projectile.NewProjectile(player.Center.X, player.Center.Y, 0f, 0f, ProjectileType <ElementShield>(), player.GetWeaponDamage(player.armor[k]), player.GetWeaponKnockback(player.armor[k], 2f), player.whoAmI, elementShields++); } } elementShieldTimer = 600; } if (heroLives > 0) { for (int k = 0; k < 200; k++) { NPC npc = Main.npc[k]; if (npc.active && npc.type == NPCType <PuritySpirit>()) { PuritySpirit modNPC = (PuritySpirit)npc.modNPC; if (modNPC.attack >= 0) { double proportion = damage / player.statLifeMax2; if (proportion > 1.0) { proportion = 1.0; } modNPC.attackWeights[modNPC.attack] += (int)(proportion * 400); if (modNPC.attackWeights[modNPC.attack] > PuritySpirit.maxAttackWeight) { modNPC.attackWeights[modNPC.attack] = PuritySpirit.maxAttackWeight; } if (nullified && modNPC.attack != 2) { modNPC.attackWeights[2] += (int)(proportion * 200); if (modNPC.attackWeights[2] > PuritySpirit.maxAttackWeight) { modNPC.attackWeights[2] = PuritySpirit.maxAttackWeight; } } } } } } }
public override void HandlePacket(BinaryReader reader, int whoAmI) { ExampleModMessageType msgType = (ExampleModMessageType)reader.ReadByte(); switch (msgType) { // This message sent by the server to initialize the Volcano Tremor on clients case ExampleModMessageType.SetTremorTime: int tremorTime = reader.ReadInt32(); ExampleWorld world = GetModWorld <ExampleWorld>(); world.VolcanoTremorTime = tremorTime; break; // This message sent by the server to initialize the Volcano Rubble. case ExampleModMessageType.VolcanicRubbleMultiplayerFix: int numberProjectiles = reader.ReadInt32(); for (int i = 0; i < numberProjectiles; i++) { int identity = reader.ReadInt32(); bool found = false; for (int j = 0; j < 1000; j++) { if (Main.projectile[j].owner == 255 && Main.projectile[j].identity == identity && Main.projectile[j].active) { Main.projectile[j].hostile = true; //Main.projectile[j].name = "Volcanic Rubble"; found = true; break; } } if (!found) { ErrorLogger.Log("Error: Projectile not found"); } } break; case ExampleModMessageType.PuritySpirit: PuritySpirit spirit = Main.npc[reader.ReadInt32()].modNPC as PuritySpirit; if (spirit != null && spirit.npc.active) { spirit.HandlePacket(reader); } break; case ExampleModMessageType.HeroLives: Player player = Main.player[reader.ReadInt32()]; int lives = reader.ReadInt32(); player.GetModPlayer <ExamplePlayer>(this).heroLives = lives; if (lives > 0) { NetworkText text; if (lives == 1) { text = NetworkText.FromKey("Mods.ExampleMod.LifeLeft", player.name); } else { text = NetworkText.FromKey("Mods.ExampleMod.LivesLeft", player.name, lives); } NetMessage.BroadcastChatMessage(text, new Color(255, 25, 25)); } break; default: ErrorLogger.Log("ExampleMod: Unknown Message type: " + msgType); break; } }
public override void HandlePacket(BinaryReader reader, int whoAmI) { ExampleModMessageType msgType = (ExampleModMessageType)reader.ReadByte(); switch (msgType) { // This message sent by the server to initialize the Volcano Tremor on clients case ExampleModMessageType.SetTremorTime: int tremorTime = reader.ReadInt32(); ExampleWorld world = GetModWorld <ExampleWorld>(); world.VolcanoTremorTime = tremorTime; break; // This message sent by the server to initialize the Volcano Rubble. case ExampleModMessageType.VolcanicRubbleMultiplayerFix: int numberProjectiles = reader.ReadInt32(); for (int i = 0; i < numberProjectiles; i++) { int identity = reader.ReadInt32(); bool found = false; for (int j = 0; j < 1000; j++) { if (Main.projectile[j].owner == 255 && Main.projectile[j].identity == identity && Main.projectile[j].active) { Main.projectile[j].hostile = true; //Main.projectile[j].name = "Volcanic Rubble"; found = true; break; } } if (!found) { Logger.Error("Error: Projectile not found"); } } break; case ExampleModMessageType.PuritySpirit: PuritySpirit spirit = Main.npc[reader.ReadInt32()].modNPC as PuritySpirit; if (spirit != null && spirit.npc.active) { spirit.HandlePacket(reader); } break; case ExampleModMessageType.HeroLives: Player player = Main.player[reader.ReadInt32()]; int lives = reader.ReadInt32(); player.GetModPlayer <ExamplePlayer>().heroLives = lives; if (lives > 0) { NetworkText text; if (lives == 1) { text = NetworkText.FromKey("Mods.ExampleMod.LifeLeft", player.name); } else { text = NetworkText.FromKey("Mods.ExampleMod.LivesLeft", player.name, lives); } NetMessage.BroadcastChatMessage(text, new Color(255, 25, 25)); } break; // This message syncs ExamplePlayer.exampleLifeFruits case ExampleModMessageType.ExamplePlayerSyncPlayer: byte playernumber = reader.ReadByte(); ExamplePlayer examplePlayer = Main.player[playernumber].GetModPlayer <ExamplePlayer>(); int exampleLifeFruits = reader.ReadInt32(); examplePlayer.exampleLifeFruits = exampleLifeFruits; examplePlayer.nonStopParty = reader.ReadBoolean(); // SyncPlayer will be called automatically, so there is no need to forward this data to other clients. break; case ExampleModMessageType.NonStopPartyChanged: playernumber = reader.ReadByte(); examplePlayer = Main.player[playernumber].GetModPlayer <ExamplePlayer>(); examplePlayer.nonStopParty = reader.ReadBoolean(); // Unlike SyncPlayer, here we have to relay/forward these changes to all other connected clients if (Main.netMode == NetmodeID.Server) { var packet = GetPacket(); packet.Write((byte)ExampleModMessageType.NonStopPartyChanged); packet.Write(playernumber); packet.Write(examplePlayer.nonStopParty); packet.Send(-1, playernumber); } break; default: Logger.WarnFormat("ExampleMod: Unknown Message type: {0}", msgType); break; } }
public override void HandlePacket(BinaryReader reader, int whoAmI) { ExampleModMessageType msgType = (ExampleModMessageType)reader.ReadByte(); switch (msgType) { // This message sent by the server to initialize the Volcano Tremor on clients case ExampleModMessageType.SetTremorTime: int tremorTime = reader.ReadInt32(); ExampleWorld world = (ExampleWorld)GetModWorld("ExampleWorld"); world.VolcanoTremorTime = tremorTime; break; // This message sent by the server to initialize the Volcano Rubble. case ExampleModMessageType.VolcanicRubbleMultiplayerFix: int numberProjectiles = reader.ReadInt32(); for (int i = 0; i < numberProjectiles; i++) { int identity = reader.ReadInt32(); bool found = false; for (int j = 0; j < 1000; j++) { if (Main.projectile[j].owner == 255 && Main.projectile[j].identity == identity && Main.projectile[j].active) { Main.projectile[j].hostile = true; Main.projectile[j].name = "Volcanic Rubble"; found = true; break; } } if (!found) { ErrorLogger.Log("Error: Projectile not found"); } } break; case ExampleModMessageType.SpawnNPC: NPC.NewNPC(reader.ReadInt32(), reader.ReadInt32(), reader.ReadInt32()); break; case ExampleModMessageType.PuritySpirit: PuritySpirit spirit = Main.npc[reader.ReadInt32()].modNPC as PuritySpirit; if (spirit != null && spirit.npc.active) { spirit.HandlePacket(reader); } break; case ExampleModMessageType.HeroLives: Player player = Main.player[reader.ReadInt32()]; int lives = reader.ReadInt32(); player.GetModPlayer <ExamplePlayer>(this).heroLives = lives; if (lives > 0) { string text = player.name + " has " + lives; if (lives == 1) { text += " life left!"; } else { text += " lives left!"; } NetMessage.SendData(25, -1, -1, text, 255, 255, 25, 25); } break; default: ErrorLogger.Log("ExampleMod: Unknown Message type: " + msgType); break; } }