예제 #1
0
 public static void SendBaseNetMessage(int msg, params object[] param)
 {
     if (Main.netMode == NetmodeID.SinglePlayer)
     {
         return;
     }                                                                   //nothing to sync in SP
     BaseNet.WriteToPacket(Fargowiltas.Instance.GetPacket(), (byte)msg, param).Send();
 }
예제 #2
0
        public override void HandlePacket(BinaryReader reader, int whoAmI)
        {
            switch (reader.ReadByte())
            {
            case 0:     //server side spawning creepers
                if (Main.netMode == 2)
                {
                    byte p          = reader.ReadByte();
                    int  multiplier = reader.ReadByte();
                    int  n          = NPC.NewNPC((int)Main.player[p].Center.X, (int)Main.player[p].Center.Y, NPCType("CreeperGutted"), 0,
                                                 p, 0f, multiplier, 0f);
                    if (n != 200)
                    {
                        Main.npc[n].velocity = Vector2.UnitX.RotatedByRandom(2 * Math.PI) * 8;
                        NetMessage.SendData(23, -1, -1, null, n);
                    }
                }
                break;

            case 1:     //server side synchronize pillar data request
                if (Main.netMode == 2)
                {
                    byte pillar = reader.ReadByte();
                    if (!Main.npc[pillar].GetGlobalNPC <FargoSoulsGlobalNPC>().masoBool[1])
                    {
                        Main.npc[pillar].GetGlobalNPC <FargoSoulsGlobalNPC>().masoBool[1] = true;
                        Main.npc[pillar].GetGlobalNPC <FargoSoulsGlobalNPC>().SetDefaults(Main.npc[pillar]);
                        Main.npc[pillar].life = Main.npc[pillar].lifeMax;
                    }
                }
                break;

            case 2:     //net updating maso
                FargoSoulsGlobalNPC fargoNPC = Main.npc[reader.ReadByte()].GetGlobalNPC <FargoSoulsGlobalNPC>();
                fargoNPC.masoBool[0] = reader.ReadBoolean();
                fargoNPC.masoBool[1] = reader.ReadBoolean();
                fargoNPC.masoBool[2] = reader.ReadBoolean();
                fargoNPC.masoBool[3] = reader.ReadBoolean();
                break;

            case 3:     //rainbow slime/paladin, MP clients syncing to server
                if (Main.netMode == 1)
                {
                    byte npc = reader.ReadByte();
                    Main.npc[npc].lifeMax = reader.ReadInt32();
                    float newScale = reader.ReadSingle();
                    Main.npc[npc].position = Main.npc[npc].Center;
                    Main.npc[npc].width    = (int)(Main.npc[npc].width / Main.npc[npc].scale * newScale);
                    Main.npc[npc].height   = (int)(Main.npc[npc].height / Main.npc[npc].scale * newScale);
                    Main.npc[npc].scale    = newScale;
                    Main.npc[npc].Center   = Main.npc[npc].position;
                }
                break;

            case 4:     //moon lord vulnerability synchronization
                if (Main.netMode == 1)
                {
                    int ML = reader.ReadByte();
                    Main.npc[ML].GetGlobalNPC <FargoSoulsGlobalNPC>().Counter = reader.ReadInt32();
                    FargoSoulsGlobalNPC.masoStateML = reader.ReadByte();
                }
                break;

            case 5:     //retinazer laser MP sync
                if (Main.netMode == 1)
                {
                    int reti = reader.ReadByte();
                    Main.npc[reti].GetGlobalNPC <FargoSoulsGlobalNPC>().masoBool[2] = reader.ReadBoolean();
                    Main.npc[reti].GetGlobalNPC <FargoSoulsGlobalNPC>().Counter     = reader.ReadInt32();
                }
                break;

            case 6:     //shark MP sync
                if (Main.netMode == 1)
                {
                    int shark = reader.ReadByte();
                    Main.npc[shark].GetGlobalNPC <FargoSoulsGlobalNPC>().SharkCount = reader.ReadByte();
                }
                break;

            case 7:     //client to server activate dark caster family
                if (Main.netMode == 2)
                {
                    int caster = reader.ReadByte();
                    if (Main.npc[caster].GetGlobalNPC <FargoSoulsGlobalNPC>().Counter2 == 0)
                    {
                        Main.npc[caster].GetGlobalNPC <FargoSoulsGlobalNPC>().Counter2 = reader.ReadInt32();
                    }
                }
                break;

            case 8:     //server to clients reset counter
                if (Main.netMode == 1)
                {
                    int caster = reader.ReadByte();
                    Main.npc[caster].GetGlobalNPC <FargoSoulsGlobalNPC>().Counter2 = 0;
                }
                break;

            case 9:     //client to server, request heart spawn
                if (Main.netMode == 2)
                {
                    int n = reader.ReadByte();
                    Item.NewItem(Main.npc[n].Hitbox, ItemID.Heart);
                }
                break;

            case 10:     //client to server, sync cultist data
                if (Main.netMode == 2)
                {
                    int cult = reader.ReadByte();
                    FargoSoulsGlobalNPC cultNPC = Main.npc[cult].GetGlobalNPC <FargoSoulsGlobalNPC>();
                    cultNPC.Counter           += reader.ReadInt32();
                    cultNPC.Counter2          += reader.ReadInt32();
                    cultNPC.Timer             += reader.ReadInt32();
                    Main.npc[cult].localAI[3] += reader.ReadSingle();
                }
                break;

            case 11:     //refresh creeper
                if (Main.netMode != 0)
                {
                    byte player  = reader.ReadByte();
                    NPC  creeper = Main.npc[reader.ReadByte()];
                    if (creeper.active && creeper.type == NPCType("CreeperGutted") && creeper.ai[0] == player)
                    {
                        int damage = creeper.lifeMax - creeper.life;
                        creeper.life = creeper.lifeMax;
                        if (damage > 0)
                        {
                            CombatText.NewText(creeper.Hitbox, CombatText.HealLife, damage);
                        }
                        if (Main.netMode == 2)
                        {
                            creeper.netUpdate = true;
                        }
                    }
                }
                break;

            case 77:     //server side spawning fishron EX
                if (Main.netMode == 2)
                {
                    byte target = reader.ReadByte();
                    int  x      = reader.ReadInt32();
                    int  y      = reader.ReadInt32();
                    FargoSoulsGlobalNPC.spawnFishronEX = true;
                    NPC.NewNPC(x, y, NPCID.DukeFishron, 0, 0f, 0f, 0f, 0f, target);
                    FargoSoulsGlobalNPC.spawnFishronEX = false;
                    NetMessage.BroadcastChatMessage(NetworkText.FromLiteral("Duke Fishron EX has awoken!"), new Color(50, 100, 255));
                }
                break;

            case 78:     //confirming fish EX max life
                int f = reader.ReadInt32();
                Main.npc[f].lifeMax = reader.ReadInt32();
                break;

            default:
                break;
            }

            //BaseMod Stuff
            MsgType msg = (MsgType)reader.ReadByte();

            if (msg == MsgType.ProjectileHostility) //projectile hostility and ownership
            {
                int  owner    = reader.ReadInt32();
                int  projID   = reader.ReadInt32();
                bool friendly = reader.ReadBoolean();
                bool hostile  = reader.ReadBoolean();
                if (Main.projectile[projID] != null)
                {
                    Main.projectile[projID].owner    = owner;
                    Main.projectile[projID].friendly = friendly;
                    Main.projectile[projID].hostile  = hostile;
                }
                if (Main.netMode == 2)
                {
                    MNet.SendBaseNetMessage(0, owner, projID, friendly, hostile);
                }
            }
            else
            if (msg == MsgType.SyncAI) //sync AI array
            {
                int     classID     = reader.ReadByte();
                int     id          = reader.ReadInt16();
                int     aitype      = reader.ReadByte();
                int     arrayLength = reader.ReadByte();
                float[] newAI       = new float[arrayLength];
                for (int m = 0; m < arrayLength; m++)
                {
                    newAI[m] = reader.ReadSingle();
                }
                if (classID == 0 && Main.npc[id] != null && Main.npc[id].active && Main.npc[id].modNPC != null && Main.npc[id].modNPC is ParentNPC)
                {
                    ((ParentNPC)Main.npc[id].modNPC).SetAI(newAI, aitype);
                }
                else
                if (classID == 1 && Main.projectile[id] != null && Main.projectile[id].active && Main.projectile[id].modProjectile != null && Main.projectile[id].modProjectile is ParentProjectile)
                {
                    ((ParentProjectile)Main.projectile[id].modProjectile).SetAI(newAI, aitype);
                }
                if (Main.netMode == 2)
                {
                    BaseNet.SyncAI(classID, id, newAI, aitype);
                }
            }
        }