Exemplo n.º 1
0
        /*public override bool AltFunctionUse(Player player)
         * {
         *  Vector2 pos = player.position; //  + new Vector2(2f * player.direction, 4f)
         *  Vector2 unitVelocity = (Main.MouseWorld - pos);
         *  unitVelocity.Normalize();
         *  Vector2 velocity = unitVelocity * 8f;
         *  Projectile projectile = Main.projectile[Projectile.NewProjectile(pos, velocity, mod.ProjectileType<ProceduralSwordThrow>(), item.damage, item.knockBack, player.whoAmI)];
         *  projectile.GetGlobalProjectile<kProjectile>().elementalDamage = item.GetGlobalItem<kItem>().elementalDamage;
         *  projectile.scale = item.scale;
         *  ProceduralSwordThrow ps = (ProceduralSwordThrow)projectile.modProjectile;
         *  ps.hilt = hilt;
         *  ps.blade = blade;
         *  ps.accent = accent;
         *  ps.sword = item;
         *  ps.Initialize();
         *  if (player.meleeDamage >= player.rangedDamage && player.meleeDamage >= player.thrownDamage)
         *      projectile.melee = true;
         *  else if (player.thrownDamage >= player.rangedDamage)
         *      projectile.thrown = true;
         *  else
         *      projectile.ranged = true;
         *  return true;
         * }*/

        public override bool UseItem(Player player)
        {
            if (spear /* && player.altFunctionUse != 2*/)
            {
                Vector2 pos          = player.position;
                Vector2 unitVelocity = (new Vector2(Main.mouseX - 12f, Main.mouseY - 24f) + Main.screenPosition - pos);
                unitVelocity.Normalize();
                Vector2    velocity   = unitVelocity * 60f / item.useAnimation;
                Projectile projectile = Main.projectile[Projectile.NewProjectile(pos, velocity, mod.GetProjectile <ProceduralSpear>().projectile.type, item.damage, item.knockBack, player.whoAmI)];
                projectile.GetGlobalProjectile <kProjectile>().elementalDamage = item.GetGlobalItem <kItem>().elementalDamage;
                projectile.scale = item.scale;
                ProceduralSpear ps = (ProceduralSpear)projectile.modProjectile;
                ps.hilt   = hilt;
                ps.blade  = blade;
                ps.accent = accent;
                if (Main.netMode != 2)
                {
                    ps.Initialize();
                }
                if (Main.netMode == 1)
                {
                    ModPacket packet = mod.GetPacket();
                    packet.Write((byte)Message.SyncSpear);
                    packet.Write(blade.type);
                    packet.Write(hilt.type);
                    packet.Write(accent.type);
                    packet.Send();
                }
                return(true);
            }

            return(false);
        }
Exemplo n.º 2
0
        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.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:
                if (Main.netMode == 2)
                {
                    Projectile projectile = Main.projectile[(int)tags[DataTag.projId]];
                    projectile.owner = (int)tags[DataTag.playerId];
                    ProceduralSpellProj ps = (ProceduralSpellProj)projectile.modProjectile;
                    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];
                    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()]);
                    }
                    ps.source.modifierOverride = modifiers;
                    foreach (Item item in ps.source.glyphs)
                    {
                        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();
                }
                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;
            }
        }
Exemplo n.º 3
0
        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;
            }
        }