public override void ReceiveExtraAI(BinaryReader reader) { projectile.owner = reader.ReadInt32(); int starType = reader.ReadInt32(); int crossType = reader.ReadInt32(); int moonType = reader.ReadInt32(); projectile.damage = reader.ReadInt32(); bool minionCaster = reader.ReadBoolean(); Caster = minionCaster ? Main.projectile[reader.ReadInt32()] : (Entity)Main.player[reader.ReadInt32()]; List <GlyphModifier> modifiers = new List <GlyphModifier>(); int count = reader.ReadInt32(); for (int i = 0; i < count; i += 1) { modifiers.Add(GlyphModifier.Modifiers[reader.ReadInt32()]); } if (Source == null) { Source = new ProceduralSpell(mod); Source.Glyphs[(byte)GlyphType.Star].SetDefaults(starType, true); Source.Glyphs[(byte)GlyphType.Cross].SetDefaults(crossType, true); Source.Glyphs[(byte)GlyphType.Moon].SetDefaults(moonType, true); Source.ModifierOverride = modifiers; } foreach (Item item in Source.Glyphs) { Glyph glyph = (Glyph)item.modItem; if (glyph.GetAiAction() != null) { Ai.Add(glyph.GetAiAction()); } if (glyph.GetInitAction() != null) { Inits.Add(glyph.GetInitAction()); } if (glyph.GetImpactAction() != null) { Impacts.Add(glyph.GetImpactAction()); } if (glyph.GetKillAction() != null) { Kills.Add(glyph.GetKillAction()); } } foreach (GlyphModifier modifier in modifiers) { if (modifier.Impact != null) { Impacts.Add(modifier.Impact); } if (modifier.Draw != null) { SpellDraw.Add(modifier.Draw); } if (modifier.Init != null) { Inits.Add(modifier.Init); } } Initialize(); }
//angle from 0f to 1f public ProceduralSpellProj CreateProjectile(Player player, Vector2 velocity, float angle = 0f, Vector2?position = null, Entity caster = null) { if (caster == null) { caster = player; } Projectile projectile = Main.projectile[ Projectile.NewProjectile(position ?? caster.Center, velocity.RotatedBy(Constants.Tau * angle), ModContent.ProjectileType <ProceduralSpellProj>(), ProjectileDamage(player.GetModPlayer <PlayerCharacter>()), 3f, player.whoAmI)]; ProceduralSpellProj ps = (ProceduralSpellProj)projectile.modProjectile; ps.Origin = projectile.position; foreach (Item item in Glyphs) { Glyph glyph = (Glyph)item.modItem; if (glyph.GetAiAction() != null) { ps.Ai.Add(glyph.GetAiAction()); } if (glyph.GetInitAction() != null) { ps.Inits.Add(glyph.GetInitAction()); } if (glyph.GetImpactAction() != null) { ps.Impacts.Add(glyph.GetImpactAction()); } if (glyph.GetKillAction() != null) { ps.Kills.Add(glyph.GetKillAction()); } } foreach (GlyphModifier modifier in Modifiers) { if (modifier.Impact != null) { ps.Impacts.Add(modifier.Impact); } if (modifier.Draw != null) { ps.SpellDraw.Add(modifier.Draw); } if (modifier.Init != null) { ps.Inits.Add(modifier.Init); } } ps.Caster = caster; ps.projectile.minion = Minion; /*if (minion) * { * ps.projectile.melee = false; * ps.projectile.ranged = false; * ps.projectile.magic = false; * }*/ ps.Source = this; ps.Initialize(); CreateProjectilePacket.Write(player.whoAmI, ps.projectile.whoAmI, Glyphs[(byte)GlyphType.Star].type, Glyphs[(byte)GlyphType.Cross].type, Glyphs[(byte)GlyphType.Moon].type, ps.projectile.damage, Minion, caster.whoAmI, Modifiers); return(ps); }
public static void Read(BinaryReader reader) { try { int playerWhoAmI = reader.ReadInt32(); int projectileWhoAmI = reader.ReadInt32(); int starType = reader.ReadInt32(); int crossType = reader.ReadInt32(); int moonType = reader.ReadInt32(); float damage = reader.ReadSingle(); bool minion = reader.ReadBoolean(); int casterWhoAmI = reader.ReadInt32(); int modCount = reader.ReadInt32(); if (Main.netMode == NetmodeID.MultiplayerClient) { if (playerWhoAmI == Main.myPlayer) { return; } } int modifierCount = modCount; List <GlyphModifier> modifiers = new List <GlyphModifier>(); for (int i = 0; i < modifierCount; i += 1) { modifiers.Add(GlyphModifier.Modifiers[reader.ReadInt32()]); } Projectile projectile = Main.projectile[projectileWhoAmI]; if (projectile == null) { return; } projectile.owner = playerWhoAmI; if (!(projectile.modProjectile is ProceduralSpellProj)) { return; } ProceduralSpellProj ps = (ProceduralSpellProj)projectile.modProjectile; ps.Source = new ProceduralSpell(kRPG.Mod) { 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(starType, true); ps.Source.Glyphs[(byte)GlyphType.Cross].SetDefaults(crossType, true); ps.Source.Glyphs[(byte)GlyphType.Moon].SetDefaults(moonType, true); projectile.damage = (int)damage; projectile.minion = minion; try { if (projectile.minion) { ps.Caster = Main.projectile[casterWhoAmI]; } else if (projectile.hostile) { ps.Caster = Main.npc[casterWhoAmI]; } else { ps.Caster = Main.player[casterWhoAmI]; } } catch (SystemException e) { kRPG.LogMessage("Source-assignment failed, aborting..." + e); return; } ps.Source.ModifierOverride = modifiers; foreach (Item item in ps.Source.Glyphs) { if (item == null) { continue; } Glyph glyph = (Glyph)item.modItem; if (glyph.GetAiAction() != null) { ps.Ai.Add(glyph.GetAiAction()); } if (glyph.GetInitAction() != null) { ps.Inits.Add(glyph.GetInitAction()); } if (glyph.GetImpactAction() != null) { ps.Impacts.Add(glyph.GetImpactAction()); } if (glyph.GetKillAction() != null) { ps.Kills.Add(glyph.GetKillAction()); } } foreach (GlyphModifier modifier in modifiers) { if (modifier.Impact != null) { ps.Impacts.Add(modifier.Impact); } if (modifier.Draw != null) { ps.SpellDraw.Add(modifier.Draw); } if (modifier.Init != null) { ps.Inits.Add(modifier.Init); } } ps.Initialize(); CreateProjectilePacket.Write(projectile.owner, projectile.whoAmI, ps.Source.Glyphs[(byte)GlyphType.Star].type, ps.Source.Glyphs[(byte)GlyphType.Cross].type, ps.Source.Glyphs[(byte)GlyphType.Moon].type, projectile.damage, projectile.minion, ps.Caster.whoAmI, modifiers ); } catch (SystemException e) { kRPG.LogMessage("Error handling packet: CreateProjectilePacket on " + (Main.netMode == NetmodeID.Server ? "serverside" : "clientSide") + ", full error trace: " + e); } }