Exemplo n.º 1
0
        public static void GetSpawnCompanionOnPlayer(BinaryReader reader, int WhoAmI) //On server, need not only to get the server WhoAmID of the character, but also send that to the player who created it, and send the updated change to other players.
        {
            byte   PlayerID        = reader.ReadByte();
            int    MyGuardianPosID = reader.ReadInt32();
            byte   AssistSlot      = reader.ReadByte();
            int    ReceivedWhoAmID = reader.ReadInt32();
            int    CompanionID     = reader.ReadInt32();
            string CompanionModID  = reader.ReadString();
            bool   Starter         = reader.ReadBoolean();
            Player player          = Main.player[PlayerID];

            if (PlayerID == Main.myPlayer)
            {
                return;
            }
            PlayerMod pm = player.GetModPlayer <PlayerMod>();

            if (!pm.MyGuardians.ContainsKey(MyGuardianPosID))
            {
                if (!pm.AddNewGuardian(CompanionID, CompanionModID, MyGuardianPosID, Starter))
                {
                    return;
                }
            }
            else
            {
                if (!pm.MyGuardians[MyGuardianPosID].MyID.IsSameID(CompanionID, CompanionModID))
                {
                    pm.MyGuardians.Remove(MyGuardianPosID);
                    if (!pm.AddNewGuardian(CompanionID, CompanionModID, MyGuardianPosID, Starter))
                    {
                        return;
                    }
                }
            }
            if (pm.GetGuardianFromSlot(AssistSlot).Active)
            {
                pm.DismissGuardian(AssistSlot);
            }
            pm.CallGuardian(MyGuardianPosID, AssistSlot);
            if (Main.netMode == 2)
            {
                int NewWhoAmID = pm.GetGuardianFromSlot(AssistSlot).WhoAmID;
                SendGuardianWhoAmIDUpdate(ReceivedWhoAmID, NewWhoAmID, WhoAmI);
                SendSpawnCompanionOnPlayer(pm, MyGuardianPosID, AssistSlot, NewWhoAmID, -1, WhoAmI);
            }
            else
            {
                pm.GetGuardianFromSlot(AssistSlot).WhoAmID = ReceivedWhoAmID;
                if (MainMod.ActiveGuardians.ContainsKey(ReceivedWhoAmID))
                {
                    do
                    {
                        MainMod.ActiveGuardians[ReceivedWhoAmID].WhoAmID = TerraGuardian.IDStack++;
                    }while (MainMod.ActiveGuardians.ContainsKey(MainMod.ActiveGuardians[ReceivedWhoAmID].WhoAmID));
                }
            }
        }