Пример #1
0
        public static void OnRemoveItem(Item item)
        {
            if (Game1.IsMasterGame)
            {
                BinListener.Unregister();

                bool removed = ModEntry.OldItems.Remove(item);
                Console.WriteLine($"Host local remove {item.Name} x{item.Stack}");
            }
        }
Пример #2
0
        public static void OnShipItem(Item item, Farmer player)
        {
            if (Game1.IsMasterGame)
            {
                BinListener.Unregister();

                Console.WriteLine($"Host local bin add {item.Name} x{item.Stack}");

                if (!ModEntry.OldItems.ContainsKey(item))//Can be called twice by the game.
                {
                    ModEntry.OldItems.Add(item, player.UniqueMultiplayerID);
                }
            }
        }
Пример #3
0
        public override void Entry(IModHelper helper)
        {
            ModHelper = helper;

            MoneyData = helper.Data.ReadJsonFile <MoneyDataModel>("moneyData.json");
            if (MoneyData == null)
            {
                Monitor.Log("Creating new moneyData.json");
                MoneyData = new MoneyDataModel();
                helper.Data.WriteJsonFile("moneyData.json", MoneyData);
            }

            Config = helper.Data.ReadJsonFile <Config>("config.json");
            if (Config == null)
            {
                Monitor.Log("Creating new config.json");
                Config = new Config();
                helper.Data.WriteJsonFile("config.json", Config);
            }

            helper.Events.GameLoop.Saved += delegate
            {
                if (Game1.IsMasterGame)
                {
                    Monitor.Log("Saving money data");
                    helper.Data.WriteJsonFile("moneyData.json", MoneyData);
                }
            };

            helper.Events.GameLoop.DayEnding += delegate
            {
                if (Game1.IsMasterGame)
                {
                    BinListener.Unregister();
                }
            };

            Patch.PatchAll("Ilyaki.CapitalistSplitMoney");
        }
Пример #4
0
        public static bool Prefix(IncomingMessage message, GameServer __instance)
        {
            Multiplayer multiplayer = ModEntry.ModHelper.Reflection.GetField <Multiplayer>(typeof(Game1), "multiplayer").GetValue();

            //Console.WriteLine($"Received packet {message.MessageType} by {message.FarmerID}/{message.SourceFarmer.Name}");

            if (message.MessageType == 13 && Game1.IsServer)
            {
                NetRoot <FarmerTeam> team = new NetRoot <FarmerTeam>(new FarmerTeam());
                team.Value.money.Minimum = null;
                multiplayer.readObjectDelta(message.Reader, team);

                int deltaMoney = team.Value.money.Value - 500;                //new FarmerTeam() has 500 as default.
                Console.WriteLine($"Delta money for {message.FarmerID}/{message.SourceFarmer.Name} = {deltaMoney}");

                if (deltaMoney != 0)
                {
                    if (ModEntry.MoneyData.PlayerMoney.ContainsKey(message.FarmerID))
                    {
                        ModEntry.MoneyData.PlayerMoney[message.FarmerID] += deltaMoney;
                    }
                    else
                    {
                        ModEntry.MoneyData.PlayerMoney.Add(message.FarmerID, Math.Max(0, ModEntry.Config.StartingMoney + deltaMoney));
                    }

                    Console.WriteLine($"{message.FarmerID} new total money = {ModEntry.MoneyData.PlayerMoney[message.FarmerID]}");

                    return(false);
                }

                #region Reset streams
                var stream = new MemoryStream(message.Data);
                var bin    = new BinaryReader(stream);

                //(msg.stream = new MemoryStream(data);)
                var streamField = ModEntry.ModHelper.Reflection.GetField <MemoryStream>(message, "stream");
                streamField.SetValue(stream);

                //(msg.reader = new BinaryReader(stream);)
                var readerField = ModEntry.ModHelper.Reflection.GetField <BinaryReader>(message, "reader");
                readerField.SetValue(bin);
                #endregion

                multiplayer.processIncomingMessage(message);

                if (multiplayer.isClientBroadcastType(message.MessageType))
                {
                    ModEntry.ModHelper.Reflection.GetMethod(__instance, "rebroadcastClientMessage").Invoke(message);
                }

                return(false);
            }
            else if (message.MessageType == 6 && Game1.IsServer)
            {
                var          readLocationMethod = ModEntry.ModHelper.Reflection.GetMethod(multiplayer, "readLocation");
                GameLocation location3          = readLocationMethod.Invoke <GameLocation>(message.Reader);
                if (location3 != null)
                {
                    Item[] ro = null;
                    if (location3 is Farm f)
                    {
                        ro = f.shippingBin.ToArray();
                    }

                    multiplayer.readObjectDelta(message.Reader, location3.Root);

                    if (location3 is Farm farm)
                    {
                        BinListener.StartListen(message.FarmerID, farm);
                    }
                }

                ModEntry.ModHelper.Reflection.GetMethod(__instance, "rebroadcastClientMessage").Invoke(message);

                return(false);
            }

            return(true);
        }