public void InitializeModifiers(NPC npc) { npc.GivenName = npc.FullName; int amount = 1; ModPacket packet; for (int i = 0; i < amount; i++) { int random = Main.rand.Next(modifierFuncs.Count); NPCModifier modifier = modifierFuncs[random].Invoke(this, npc); modifiers.Add(modifier); } if (Main.netMode == 2) { packet = mod.GetPacket(); packet.Write((byte)Message.PrefixNPC); packet.Write(npc.whoAmI); packet.Write(amount); for (int i = 0; i < amount; i++) { packet.Write(modifiers.FindIndex(modifier => modifier == modifiers[i])); modifiers[i].Write(packet); } packet.Send(); } MakeNotable(npc); }
static public void HandlePacket(BinaryReader reader, int whoAmI) { Message msg = (Message)reader.ReadByte(); Dictionary <DataTag, object> tags = new Dictionary <DataTag, object>(); foreach (DataTag tag in dataTags[msg]) { tags.Add(tag, tag.read(reader)); } switch (msg) { case Message.SyncLevel: RPGPlayer p = Main.player[(int)tags[DataTag.playerId]].GetModPlayer <RPGPlayer>(); if (p.baseName == "") { p.baseName = Main.player[(int)tags[DataTag.playerId]].name; } if ((int)tags[DataTag.playerId] != Main.myPlayer) { if (Main.netMode != NetmodeID.SinglePlayer) { p.SyncLevel((int)tags[DataTag.amount]); } Main.player[(int)tags[DataTag.playerId]].name = p.baseName + " The Lvl." + p.GetLevel() + " " + (string)tags[DataTag.buffer]; } break; case Message.AddXP: Main.LocalPlayer.GetModPlayer <RPGPlayer>().AddXp((int)tags[DataTag.amount], (int)tags[DataTag.level]); break; case Message.SyncNPCSpawn: if (Main.netMode == NetmodeID.MultiplayerClient) { NPC npc = Main.npc[(int)tags[DataTag.npcId]]; if (npc.GetGlobalNPC <ARPGGlobalNPC>() == null) { AnotherRpgMod.Instance.Logger.Info(npc.GivenName); } //npc.SetDefaults(npc.type); if (npc.GetGlobalNPC <ARPGGlobalNPC>().StatsCreated == true) { return; } int tier = (int)tags[DataTag.tier]; int level = (int)tags[DataTag.level]; NPCRank rank = (NPCRank)tags[DataTag.rank]; NPCModifier modifiers = (NPCModifier)tags[DataTag.modifiers]; if (npc == null || npc.GetGlobalNPC <ARPGGlobalNPC>() == null) { return; } AnotherRpgMod.Instance.Logger.Info(npc.GivenOrTypeName + "\nTier : " + tier + " Level : " + level + " rank : " + rank + " Modifier : " + modifiers + " \n Buffer : " + (string)tags[DataTag.buffer]); Dictionary <string, string> bufferStack = Unparse((string)tags[DataTag.buffer]); WorldManager.BossDefeated = (int)tags[DataTag.WorldTier]; npc.GetGlobalNPC <ARPGGlobalNPC>().StatsCreated = true; npc.GetGlobalNPC <ARPGGlobalNPC>().modifier = modifiers; npc.GetGlobalNPC <ARPGGlobalNPC>().SetLevelTier(level, tier, (byte)rank); npc.GetGlobalNPC <ARPGGlobalNPC>().specialBuffer = bufferStack; npc.GetGlobalNPC <ARPGGlobalNPC>().SetStats(npc); npc.GivenName = NPCUtils.GetNpcNameChange(npc, tier, level, rank); //AnotherRpgMod.Instance.Logger.Info("NPC created with id : " + npc.whoAmI); //AnotherRpgMod.Instance.Logger.Info( "Client Side : \n" + npc.GetGivenOrTypeNetName() + "\nLvl." + (npc.GetGlobalNPC<ARPGGlobalNPC>().getLevel + npc.GetGlobalNPC<ARPGGlobalNPC>().getTier) + "\nHealth : " + npc.life + " / " + npc.lifeMax + "\nDamage : " + npc.damage + "\nDef : " + npc.defense + "\nTier : " + npc.GetGlobalNPC<ARPGGlobalNPC>().getRank + "\n\n"); } break; case Message.SyncNPCUpdate: if (Main.netMode == NetmodeID.MultiplayerClient) { NPC npcu = Main.npc[(int)tags[DataTag.npcId]]; if (npcu.lifeMax != (int)tags[DataTag.maxLife] || npcu.life != (int)tags[DataTag.life]) { AnotherRpgMod.Instance.Logger.Warn("DESYNC ERROR SPOTTED FOR : "); AnotherRpgMod.Instance.Logger.Warn(npcu.GivenOrTypeName + "\n" + (int)tags[DataTag.life] + " / " + (int)tags[DataTag.maxLife] + "\n" + npcu.life + " / " + npcu.lifeMax); } Main.npc[(int)tags[DataTag.npcId]].lifeMax = (int)tags[DataTag.maxLife]; Main.npc[(int)tags[DataTag.npcId]].life = (int)tags[DataTag.life]; } break; case Message.Log: if (Main.netMode == NetmodeID.MultiplayerClient) { //ErrorLogger.Log("LOG FROM SERVER"); AnotherRpgMod.Instance.Logger.Info((string)tags[DataTag.buffer]); } break; case Message.AskNpc: if (Main.netMode == NetmodeID.Server) { NPC npc = Main.npc[(int)tags[DataTag.npcId]]; if (npc.GetGlobalNPC <ARPGGlobalNPC>() == null) { return; } int tier = npc.GetGlobalNPC <ARPGGlobalNPC>().getTier; int level = npc.GetGlobalNPC <ARPGGlobalNPC>().getLevel; int rank = npc.GetGlobalNPC <ARPGGlobalNPC>().getRank; Mod mod = AnotherRpgMod.Instance; //MPDebug.Log(mod, "Server Side : \n" + npc.GetGivenOrTypeNetName() + " ID : " + npc.whoAmI + "\nLvl." + (npc.GetGlobalNPC<ARPGGlobalNPC>().getLevel + npc.GetGlobalNPC<ARPGGlobalNPC>().getTier) + "\nHealth : " + npc.life + " / " + npc.lifeMax + "\nDamage : " + npc.damage + "\nDef : " + npc.defense + "\nTier : " + npc.GetGlobalNPC<ARPGGlobalNPC>().getRank + "\n"); SendNpcSpawn(mod, npc, tier, level, npc.GetGlobalNPC <ARPGGlobalNPC>()); } break; } }
public void SetInit(NPC npc) { if (Main.netMode == 2) { Main.npcLifeBytes[npc.type] = 4; //Sadly have to UN-optimise Health of ennemy, because it caused npc to dispear if health was over 128 (for small ) } if (Main.netMode != 1) { if (level < 0) { if (!Config.gpConfig.NPCProgress) { level = 0; tier = 0; } else { level = Mathf.CeilInt(NPCUtils.GetBaseLevel(npc) * Config.gpConfig.NpclevelMultiplier); if (npc.townNPC || (npc.damage == 0)) { tier = Mathf.CeilInt(NPCUtils.GetTierAlly(npc, level) * Config.gpConfig.NpclevelMultiplier); } else if (Config.gpConfig.NPCProgress) { tier = Mathf.CeilInt(NPCUtils.GetTier(npc, level) * Config.gpConfig.NpclevelMultiplier); } } if (!npc.townNPC && !(npc.damage == 0) && (!npc.dontCountMe)) { Rank = NPCUtils.GetRank(level + tier); modifier = NPCUtils.GetModifier(Rank, npc); if (HaveModifier(NPCModifier.Size)) { int maxrng = Main.expertMode ? 50 : 70; int rn = Mathf.RandomInt(0, maxrng); if (npc.boss) { rn += 1; } if (rn < 1) { SetBufferProperty("size", "Growther"); SetBufferProperty("GrowtherStep", "Mini"); } else if (rn < 3) { SetBufferProperty("size", "Titan"); } else if (rn < 6) { SetBufferProperty("size", "Colossus"); } else if (rn < 20) { SetBufferProperty("size", "Giant"); } else { SetBufferProperty("size", "Mini"); } } } } } }
public bool HaveModifier(NPCModifier _modifier) { return((_modifier & modifier) == _modifier); }
public override void HandlePacket(BinaryReader reader, int whoAmI) { Message msg = (Message)reader.ReadByte(); Dictionary <DataTag, object> tags = new Dictionary <DataTag, object>(); foreach (DataTag tag in dataTags[msg]) { tags.Add(tag, tag.read(reader)); } switch (msg) { //case Message.InitProjEleDmg: // if (!Main.projectile.IndexInRange((int)tags[DataTag.projId])) break; // Projectile p = Main.projectile[(int)tags[DataTag.projId]]; // try // { // kProjectile proj = p.GetGlobalProjectile<kProjectile>(); // proj.elementalDamage = new Dictionary<ELEMENT, int>() // { // { ELEMENT.FIRE, (int)tags[DataTag.fire] }, // { ELEMENT.COLD, (int)tags[DataTag.cold] }, // { ELEMENT.LIGHTNING, (int)tags[DataTag.lightning] }, // { ELEMENT.SHADOW, (int)tags[DataTag.shadow] } // }; // } // catch (SystemException e) // { // Main.NewText(e.ToString()); // } // break; case Message.NPCEleDmg: if (Main.netMode == 1) { NPC npc = Main.npc[(int)tags[DataTag.npcId]]; kNPC kn = npc.GetGlobalNPC <kNPC>(); Dictionary <ELEMENT, bool> haselement = new Dictionary <ELEMENT, bool>() { { ELEMENT.FIRE, (bool)tags[DataTag.flag] }, { ELEMENT.COLD, (bool)tags[DataTag.flag2] }, { ELEMENT.LIGHTNING, (bool)tags[DataTag.flag3] }, { ELEMENT.SHADOW, (bool)tags[DataTag.flag4] } }; int count = 0; foreach (ELEMENT element in Enum.GetValues(typeof(ELEMENT))) { if (haselement[element]) { count += 1; } } int portionsize = (int)Math.Round((double)npc.damage * kNPC.ELE_DMG_MODIFIER / 2.0 / count); foreach (ELEMENT element in Enum.GetValues(typeof(ELEMENT))) { if (haselement[element]) { kn.elementalDamage[element] = Math.Max(1, portionsize); } } kn.dealseledmg = count > 0; } break; case Message.PrefixNPC: if (Main.netMode == 1) { NPC npc = Main.npc[(int)tags[DataTag.npcId]]; kNPC kn = npc.GetGlobalNPC <kNPC>(); for (int i = 0; i < (int)tags[DataTag.amount]; i += 1) { NPCModifier modifier = kn.modifierFuncs[reader.ReadInt32()].Invoke(kn, npc); modifier.Read(reader); modifier.Apply(); kn.modifiers.Add(modifier); } kn.MakeNotable(npc); } break; case Message.SyncStats: if (Main.netMode == 2) { PlayerCharacter character = Main.player[(int)tags[DataTag.playerId]].GetModPlayer <PlayerCharacter>(); character.level = (int)tags[DataTag.amount]; character.baseStats[STAT.RESILIENCE] = (int)tags[DataTag.resilience]; character.baseStats[STAT.QUICKNESS] = (int)tags[DataTag.quickness]; character.baseStats[STAT.POTENCY] = (int)tags[DataTag.potency]; character.baseStats[STAT.WITS] = (int)tags[DataTag.wits]; } break; case Message.SyncLevel: if (Main.netMode == 2) { Main.player[(int)tags[DataTag.playerId]].GetModPlayer <PlayerCharacter>().level = (int)tags[DataTag.amount]; } break; case Message.CreateProjectile: try { if (Main.netMode == 1) { if ((int)tags[DataTag.playerId] == Main.myPlayer) { break; } } int modifierCount = (int)tags[DataTag.modifierCount]; List <GlyphModifier> modifiers = new List <GlyphModifier>(); for (int i = 0; i < modifierCount; i += 1) { modifiers.Add(GlyphModifier.modifiers[reader.ReadInt32()]); } Projectile projectile = Main.projectile[(int)tags[DataTag.projId]]; if (projectile == null) { break; } projectile.owner = (int)tags[DataTag.playerId]; if (!(projectile.modProjectile is ProceduralSpellProj)) { break; } ProceduralSpellProj ps = (ProceduralSpellProj)projectile.modProjectile; ps.source = new ProceduralSpell(mod); ps.source.glyphs = new Item[3]; for (int i = 0; i < ps.source.glyphs.Length; i += 1) { ps.source.glyphs[i] = new Item(); ps.source.glyphs[i].SetDefaults(0, true); } ps.source.glyphs[(byte)GLYPHTYPE.STAR].SetDefaults((int)tags[DataTag.glyph_star], true); ps.source.glyphs[(byte)GLYPHTYPE.CROSS].SetDefaults((int)tags[DataTag.glyph_cross], true); ps.source.glyphs[(byte)GLYPHTYPE.MOON].SetDefaults((int)tags[DataTag.glyph_moon], true); projectile.damage = (int)tags[DataTag.damage]; projectile.minion = (bool)tags[DataTag.flag]; try { if (projectile.minion) { ps.caster = Main.projectile[(int)tags[DataTag.entityId]]; } else if (projectile.hostile) { ps.caster = Main.npc[(int)tags[DataTag.entityId]]; } else { ps.caster = Main.player[(int)tags[DataTag.entityId]]; } } catch (SystemException e) { ErrorLogger.Log("Source-assignment failed, aborting..."); break; } ps.source.modifierOverride = modifiers; foreach (Item item in ps.source.glyphs) { if (item != null) { Glyph glyph = (Glyph)item.modItem; if (glyph.GetAIAction() != null) { ps.ai.Add(glyph.GetAIAction()); } if (glyph.GetInitAction() != null) { ps.init.Add(glyph.GetInitAction()); } if (glyph.GetImpactAction() != null) { ps.impact.Add(glyph.GetImpactAction()); } if (glyph.GetKillAction() != null) { ps.kill.Add(glyph.GetKillAction()); } } } foreach (GlyphModifier modifier in modifiers) { if (modifier.impact != null) { ps.impact.Add(modifier.impact); } if (modifier.draw != null) { ps.draw.Add(modifier.draw); } if (modifier.init != null) { ps.init.Add(modifier.init); } } ps.Initialize(); if (Main.netMode == 2) { ModPacket packet = mod.GetPacket(); packet.Write((byte)Message.CreateProjectile); packet.Write(projectile.owner); packet.Write(projectile.whoAmI); packet.Write(ps.source.glyphs[(byte)GLYPHTYPE.STAR].type); packet.Write(ps.source.glyphs[(byte)GLYPHTYPE.CROSS].type); packet.Write(ps.source.glyphs[(byte)GLYPHTYPE.MOON].type); packet.Write(projectile.damage); packet.Write(projectile.minion); packet.Write(ps.caster.whoAmI); List <GlyphModifier> mods = modifiers; packet.Write(mods.Count); for (int j = 0; j < mods.Count; j += 1) { packet.Write(mods[j].id); } packet.Send(); } } catch (SystemException e) { ErrorLogger.Log("Error handling packet: " + msg.ToString() + " on " + (Main.netMode == 2 ? "serverside" : "clientside") + ", full error trace: " + e.ToString()); } break; case Message.AddXP: if (Main.netMode == 1) { //Player player = Main.player[Main.myPlayer]; //if (Vector2.Distance(player.Center, Main.npc[(int)tags[DataTag.npcId]].Center) > 1024) // break; PlayerCharacter character = Main.LocalPlayer.GetModPlayer <PlayerCharacter>(); character.AddXP((int)tags[DataTag.amount]); } break; case Message.SyncSpear: ProceduralSpear spear = (ProceduralSpear)Main.projectile[(int)tags[DataTag.projId]].modProjectile; spear.blade = SwordBlade.blades[(int)tags[DataTag.partPrimary]]; spear.hilt = SwordHilt.hilts[(int)tags[DataTag.partSecondary]]; spear.accent = SwordAccent.accents[(int)tags[DataTag.partTertiary]]; if (Main.netMode == 1) { spear.Initialize(); } break; case Message.SwordInit: if (Main.netMode == 1) { ProceduralSword sword = (ProceduralSword)Main.item[(int)tags[DataTag.itemId]].modItem; sword.blade = SwordBlade.blades[(int)tags[DataTag.partPrimary]]; sword.hilt = SwordHilt.hilts[(int)tags[DataTag.partSecondary]]; sword.accent = SwordAccent.accents[(int)tags[DataTag.partTertiary]]; sword.dps = (float)tags[DataTag.itemDps]; Main.NewText(sword.dps.ToString()); sword.enemyDef = (int)tags[DataTag.itemDef]; sword.Initialize(); } break; case Message.StaffInit: if (Main.netMode == 1) { ProceduralStaff staff = (ProceduralStaff)Main.item[(int)tags[DataTag.itemId]].modItem; staff.staff = Staff.staves[(int)tags[DataTag.partPrimary]]; staff.gem = StaffGem.gems[(int)tags[DataTag.partSecondary]]; staff.ornament = StaffOrnament.ornament[(int)tags[DataTag.partTertiary]]; staff.dps = (float)tags[DataTag.itemDps]; staff.enemyDef = (int)tags[DataTag.itemDef]; staff.Initialize(); } break; case Message.BowInit: if (Main.netMode == 1) { RangedWeapon bow = (RangedWeapon)Main.item[(int)tags[DataTag.itemId]].modItem; bow.dps = (float)tags[DataTag.itemDps]; bow.enemyDef = (int)tags[DataTag.itemDef]; bow.Initialize(); } break; case Message.SyncHit: if (Main.netMode == 1) { PlayerCharacter character = Main.player[(int)tags[DataTag.playerId]].GetModPlayer <PlayerCharacter>(); character.accuracyCounter = (float)tags[DataTag.amount_single]; } break; case Message.SyncCritHit: if (Main.netMode == 1) { PlayerCharacter character = Main.player[(int)tags[DataTag.playerId]].GetModPlayer <PlayerCharacter>(); character.critAccuracyCounter = (float)tags[DataTag.amount_single]; } break; } }
public static NPCModifier GetModifier(NPCRank rank, NPC npc) { if (npc.dontCountMe) { return(NPCModifier.None); } if (!Config.NPCConfig.NPCModifier) { return(NPCModifier.None); } if (npc.boss && !Config.NPCConfig.BossModifier) { return(NPCModifier.None); } int maxModifier = 1; switch (rank) { case NPCRank.Weak: return(0); case NPCRank.Normal: maxModifier = (Mathf.Random(0, 3) < 1) ? 0 : 1; break; case NPCRank.Alpha: maxModifier = 1; break; case NPCRank.Elite: maxModifier = (Mathf.Random(0, 3) < 1) ? 1 : 2; break; case NPCRank.Legendary: maxModifier = 2; break; case NPCRank.Mythical: maxModifier = 3; break; case NPCRank.Godly: maxModifier = 4; break; case NPCRank.DIO: maxModifier = (Enum.GetValues(typeof(NPCModifier)) as NPCModifier[]).Length; break; } NPCModifier modifiers = 0; //if npc.aiStyle == 3 List <NPCModifier> modifiersPool = (Enum.GetValues(typeof(NPCModifier)) as NPCModifier[]).ToList(); if (npc.boss) { modifiersPool.Remove(NPCModifier.Size); if (maxModifier == (Enum.GetValues(typeof(NPCModifier)) as NPCModifier[]).Length) { maxModifier -= 1; } if (!Config.NPCConfig.BossClustered) { modifiersPool.Remove(NPCModifier.Cluster); if (maxModifier + 1 == (Enum.GetValues(typeof(NPCModifier)) as NPCModifier[]).Length) { maxModifier -= 1; } } } else if (npc.type == NPCID.EaterofWorldsHead || npc.type == NPCID.EaterofWorldsBody || npc.type == NPCID.EaterofWorldsTail) { modifiersPool.Remove(NPCModifier.Cluster); modifiersPool.Remove(NPCModifier.Size); if (maxModifier == (Enum.GetValues(typeof(NPCModifier)) as NPCModifier[]).Length) { maxModifier -= 2; } } for (int i = 0; i < maxModifier; i++) { NPCModifier modid = AddRandomModifier(modifiersPool); modifiers = modifiers | modid; modifiersPool.Remove(modid); } return(modifiers); }