Example #1
0
        public static void EndInvasion()
        {
            var myworld = ModContent.GetInstance <DynamicInvasionsWorld>();

            if (Main.netMode == 0)
            {
                myworld.Logic.EndInvasion();
            }
            else if (Main.netMode == 1)
            {
                ClientPacketHandlers.SendEndInvasionRequestFromClient();
            }
            else if (Main.netMode == 2)
            {
                myworld.Logic.EndInvasion();

                for (int i = 0; i < Main.player.Length; i++)
                {
                    Player player = Main.player[i];
                    if (player == null || !player.active)
                    {
                        continue;
                    }

                    ServerPacketHandlers.SendEndInvasionFromServer(player);
                }
            }
        }
        public override void RightClick(Player player)
        {
            var config  = DynamicInvasionsMod.Config;
            var myworld = ModContent.GetInstance <DynamicInvasionsWorld>();

            if (config.CanAbortInvasions && myworld.Logic.IsInvasionHappening())
            {
                Item fuelItem = CrossDimensionalAggregatorItem.GetFuelItemFromInventory(player);
                int  fuelAmt  = fuelItem != null && !fuelItem.IsAir
                                        ? fuelItem.stack
                                        : 0;

                if (config.InvasionAbortFuelCost == 0 || fuelAmt >= config.InvasionAbortFuelCost)
                {
                    if (config.InvasionAbortFuelCost > 0)
                    {
                        ItemHelpers.ReduceStack(fuelItem, config.InvasionAbortFuelCost);
                    }

                    Main.NewText("Ending invasion...");

                    if (Main.netMode == 0)
                    {
                        myworld.Logic.EndInvasion();
                    }
                    else if (Main.netMode == 1)
                    {
                        ClientPacketHandlers.SendEndInvasionRequestFromClient();
                    }
                }
                else
                {
                    Main.NewText("You need " + config.InvasionAbortFuelCost + " Eternia Crystals to abort an invasion.", Color.Yellow);
                }
            }
            else
            {
                Main.NewText("No custom invasion in progress.", Color.Yellow);
            }
        }