public override void HandlePacket(BinaryReader reader, int whoAmI)
        {
            //In case i f*ck the code
            try
            {
                string type = reader.ReadString();
#if DEBUG
                Main.NewText($"Received packet: [c/ff3333:{type}]");
#endif
                switch (type)
                {
                case SpawnStarterPacket.NAME:
                {
                    //Server can't have any UI
                    if (whoAmI == 256)
                    {
                        return;
                    }
                    SpawnStarterPacket packet = new SpawnStarterPacket();
                    packet.HandleFromClient(reader, whoAmI);
                }
                break;

                case BaseCatchPacket.NAME:
                {
                    //Server should handle it from client
                    if (whoAmI == 256)
                    {
                        return;
                    }
                    BaseCatchPacket packet = new BaseCatchPacket();
                    packet.HandleFromClient(reader, whoAmI);
                }
                break;

                default:
                    if (packetStore.ContainsKey(type))
                    {
                        if (whoAmI == 256)
                        {
                            packetStore[type].HandleFromServer(reader);
                        }
                        else
                        {
                            packetStore[type].HandleFromClient(reader, whoAmI);
                        }
                    }
                    break;
                }
            }
            catch (Exception e)
            {
                Logger.ErrorFormat(
                    "Exception appear in HandlePacket. Please, contact mod devs with folowing stacktrace:\n\n{0}\n\n{1}",
                    e.Message, e.StackTrace);
#if DEBUG
                Main.NewText($"[c/ff3322:{e.Message}]");
#endif
            }
        }
Beispiel #2
0
        private void Catch(ref Projectile proj, ref bool crit, ref int dmg, int type)
        {
            var PokeNam = Regex.Replace(HomeClass().Name, nameMatcher, "$1 ");

            if (pokeName.Value != PokeNam)
            {
                pokeName = TerramonMod.Localisation.GetLocalisedString(new LocalisedString(PokeNam));
            }
            proj.ai[1] = 2;
            crit       = false;
            dmg        = npc.lifeMax;
            CreateDust(4);
            CombatText.NewText(npc.Hitbox, Color.Orange, $"{pokeName.Value} was caught!", true);

            if (Main.netMode == NetmodeID.MultiplayerClient)
            {
                var packet = new BaseCatchPacket();
                packet.Send((TerramonMod)mod, HomeClass().Name, npc.TypeName, npc.getRect(), type, shiny);
            }
            else
            {
                if (Main.netMode == NetmodeID.Server)
                {
                    BaseCaughtClass.writeDetour(HomeClass().Name, npc.TypeName, GetSmallSpritePath(npc), 1, "", shiny);
                }

                int index = Item.NewItem(npc.getRect(), type);
                if (index >= 400)
                {
                    return;
                }

                if (Main.netMode == NetmodeID.Server)
                {
                    return;
                }

                if (!(Main.item[index].modItem is BaseCaughtClass item))
                {
                    return;
                }
                item.PokemonName = npc.TypeName;
                if (shiny)
                {
                    item.isShiny = true;
                }
                else
                {
                    item.isShiny = false;
                }

                item.CapturedPokemon = HomeClass().Name;
            }
        }
        public override void UpdateInventory(Player player)
        {
            currentWaitTime++;
            if (currentWaitTime < WaitTime * 60)
            {
                return;
            }

            if (PokemonName == null || PokemonName == string.Empty)
            {
                item.TurnToAir();//This is invalid item
                return;
            }

            ParentPokemon hatchedPokemon = TerramonMod.GetPokemon(PokemonName);
            string        pokemonName    = hatchedPokemon?.GetType().Name;

            if (player.whoAmI != Main.myPlayer)
            {
                return;
            }

            switch (Main.netMode)
            {
            case NetmodeID.MultiplayerClient:
            {
                var packet = new BaseCatchPacket();
                packet.Send((TerramonMod)mod, pokemonName, pokemonName, player.getRect(),
                            ItemType <PokeballCaught>());
                break;
            }

            case NetmodeID.Server:
            {
                BaseCaughtClass.writeDetour(pokemonName, pokemonName,
                                            GetSmallSpritePath(pokemonName), 1, "", false); //This force server to write data when SetDefault() was called
                Item.NewItem(player.position, ItemType <PokeballCaught>());                 // Within this call SetDefault was called
                break;
            }

            default:
            {
                int             pokeballIndex = Item.NewItem(player.position, ItemType <PokeballCaught>());
                BaseCaughtClass pokeballItem  = Main.item[pokeballIndex].modItem as BaseCaughtClass;
                pokeballItem.PokemonName     = pokeballItem.CapturedPokemon = pokemonName;
                pokeballItem.SmallSpritePath = GetSmallSpritePath(pokemonName);
                break;
            }
            }

            Main.NewText(player.name + " the " + pokemonName + " Egg has hatched!", Color.Orange);
            player.ConsumeItem(item.type);
            currentWaitTime = 0;
        }
        private void EvolveButtonClicked(UIMouseEvent evt, UIElement listeningElement)
        {
            int whicheverballtype = TerramonMod.PokeballFactory.GetPokeballType(partyslot1.Item.modItem);

            // stuff break
            if (partyslot1.Item.modItem is BaseCaughtClass pokeball)
            {
                var mon = TerramonMod.GetPokemon(pokeball.CapturedPokemon);
                if (mon == null)
                {
                    Main.NewText("This Pokémon cannot evolve!");
                    return;
                }

                var evolved = TerramonMod.GetPokemon(mon.EvolveTo.Name);
                if (evolved == null)
                {
                    Main.NewText("This Pokémon cannot evolve!");
                    return;
                }

                if (Main.netMode == NetmodeID.MultiplayerClient)
                {
                    BaseCatchPacket packet = new BaseCatchPacket();
                    packet.Send(TerramonMod.Instance, evolved.GetType().Name, evolved.GetType().Name, Main.LocalPlayer.getRect(), whicheverballtype);
                }
                else
                {
                    int index = Item.NewItem(Main.LocalPlayer.getRect(), whicheverballtype);
                    if (index >= 400)
                    {
                        return;
                    }
                    if (Main.item[index].modItem is BaseCaughtClass item)
                    {
                        item.PokemonName     = evolved.GetType().Name;
                        item.CapturedPokemon = evolved.GetType().Name;
                    }
                }
            }

            Visible = false;
            partyslot1.Item.TurnToAir();
            partyslot2.Item.TurnToAir();
            mainPanel.RemoveChild(SaveButton);
            Main.LocalPlayer.talkNPC = 0;
        }
        public override void HandlePacket(BinaryReader reader, int whoAmI)
        {
            //In case i f*ck the code
            try
            {
                string type = reader.ReadString();
                switch (type)
                {
                case SpawnStarterPacket.NAME:
                {
                    //Server can't have any UI
                    if (whoAmI == 256)
                    {
                        return;
                    }
                    SpawnStarterPacket packet = new SpawnStarterPacket();
                    packet.HandleFromClient(reader, whoAmI);
                }
                break;

                case BaseCatchPacket.NAME:
                {
                    //Server should handle it from client
                    if (whoAmI == 256)
                    {
                        return;
                    }
                    BaseCatchPacket packet = new BaseCatchPacket();
                    packet.HandleFromClient(reader, whoAmI);
                }
                break;
                }
            }
            catch (Exception e)
            {
                Logger.ErrorFormat(
                    "Exception appear in HandlePacket. Please, contact mod devs with folowing stacktrace:\n\n{0}\n\n{1}",
                    e.Message, e.StackTrace);
            }
        }