private static void sendInstruction <T>(string assetName, T asset, ContentType type, bool toGameContent, Farmer farmer, Action <bool> callback, int timeout)
        {
            if (contentPipe.ContainsKey(farmer) && contentPipe[farmer].Contains(assetName))
            {
                return;
            }

            if (contentPipe.ContainsKey(farmer))
            {
                contentPipe[farmer].AddOrReplace(assetName);
            }
            else
            {
                contentPipe.Add(farmer, new List <string>()
                {
                    assetName
                });
            }

            Task.Run(async() =>
            {
                await PyNet.sendRequestToFarmer <bool>(receiverName, new ContentResponse(assetName, (int)type, serialize(asset, type), toGameContent), farmer, (r) =>
                {
                    if (!r)
                    {
                        callback(false);
                    }
                    else
                    {
                        callback(r);
                    }
                }, SerializationType.JSON, timeout);
            });
        }
        internal static bool canBeRebuildInMultiplayer(object obj)
        {
            if (!(getDataString(obj).StartsWith(newPrefix) || getDataString(obj).StartsWith(oldPrefix)))
            {
                return(false);
            }

            string dataString = getDataString(obj);

            preProcessors.useAll(p => dataString = p.Invoke(dataString));

            dataString = dataString.Replace(" " + valueSeperator.ToString() + " ", valueSeperator.ToString());
            string[] data = splitElemets(dataString);

            bool result = true;

            if (typeCheckCache.Contains(data[2]))
            {
                return(true);
            }

            foreach (Farmer farmer in Game1.otherFarmers.Values.Where(f => f.isActive() && f != Game1.player))
            {
                Task <bool> fResult = PyNet.sendRequestToFarmer <bool>(typeCheckerName, data[2], farmer);
                fResult.Wait();
                result = result && fResult.Result;
            }

            if (result)
            {
                typeCheckCache.Add(data[2]);
            }

            return(result);
        }
Beispiel #3
0
 internal static void sendMoney(Farmer receiver, int money)
 {
     Task.Run(async() =>
     {
         await PyNet.sendRequestToFarmer <bool>(moneyReceiverName, money, receiver, (b) => { if (!b)
                                                                                             {
                                                                                                 Game1.player.Money += money;
                                                                                             }
                                                }, SerializationType.PLAIN, 3000);
     });
 }
 private static void getResponse <T>(string assetName, ContentType type, bool fromGameContent, Farmer farmer, Action <T> callback, Func <ContentResponse, T> deserializer, int timeout)
 {
     Task.Run(async() =>
     {
         await PyNet.sendRequestToFarmer <ContentResponse>(responderName, new ContentRequest(type, assetName, fromGameContent), farmer, (r) =>
         {
             if (r.content == "na")
             {
                 PyTKMod._monitor.Log("ContentRequest Failed: Could not obtain asset: " + r.assetName);
                 callback((T)(object)null);
             }
             else
             {
                 callback(deserializer(r));
             }
         }, SerializationType.JSON, timeout);
     });
 }
Beispiel #5
0
 private static void sendInstruction <T>(string[] assetName, T asset, ContentType type, bool toGameContent, Farmer farmer, Action <bool> callback, int timeout)
 {
     Task.Run(async() =>
     {
         await PyNet.sendRequestToFarmer <bool>(receiverName, new ContentResponse(String.Join("|", assetName), (int)type, serialize(asset, type), toGameContent), farmer, (r) =>
         {
             if (!r)
             {
                 PyTKMod._monitor.Log("ContentRequest Failed: Could not send asset: " + String.Join("|", assetName) + " to " + farmer.Name);
                 callback(false);
             }
             else
             {
                 callback(r);
             }
         }, SerializationType.JSON, timeout);
     });
 }
        public static void setScore(string name, int score)
        {
            Highscore highscore = new Highscore(name, score);
            var       oldEntry  = HighscoreTable.Entries.Find(entry => entry.Name == name && entry.Value >= score);

            if (!(oldEntry is Highscore))
            {
                HighscoreTable.Entries.Add(highscore);
                SnakeMod.monitor.Log("New Highscore!");
                SnakeMod.monitor.Log(highscore.Name + ": " + highscore.Value);
                if (Game1.IsMasterGame)
                {
                    PyNet.sendRequestToAllFarmers <bool>(SnakeMod.highscoreListReceiverName, HighscoreTable, null, serializationType: PyTK.Types.SerializationType.JSON);
                }
                else
                {
                    Task.Run(async() => await PyNet.sendRequestToFarmer <bool>(SnakeMod.highscoreReceiverName, highscore, Game1.MasterPlayer, serializationType: PyTK.Types.SerializationType.JSON));
                }
            }
        }
Beispiel #7
0
 internal static bool Prefix(Farmer receiver, ProposalType proposalType, Item gift)
 {
     if (proposalType == ProposalType.Gift && gift is GoldItem)
     {
         int money = Game1.player.ActiveObject.Stack;
         Task.Run(async() =>
         {
             await PyNet.sendRequestToFarmer <bool>(moneyReceiverName, money, receiver, (b) => { if (!b)
                                                                                                 {
                                                                                                     Game1.player.Money += money;
                                                                                                 }
                                                    }, SerializationType.PLAIN, 3000);
         });
         Game1.player.removeItemFromInventory(Game1.player.ActiveObject);
         return(false);
     }
     else
     {
         return(true);
     }
 }
Beispiel #8
0
        public static void Prefix_drawHairAndAccesories(FarmerRenderer __instance, Farmer who, int facingDirection, Vector2 position, Vector2 origin, float scale, int currentFrame, float rotation, Color overrideColor)
        {
            if (Game1.activeClickableMenu is TitleMenu && who.hat.Value is Hat h && !(h is CustomHat) && SaveHandler.getAdditionalSaveData(h) is Dictionary <string, string> savdata)
            {
                if (savdata.ContainsKey("blueprint") && savdata["blueprint"] is string bid && CustomShirtsMod.hats.Find(bp => bp.fullid == bid) is HatBlueprint hbp)
                {
                    who.hat.Value = new CustomHat(hbp);
                }
            }

            if (who.hat.Value is CustomHat c)
            {
                if (c.texture == null && CustomShirtsMod.syncedHats.ContainsKey(c.hatId + "." + who.UniqueMultiplayerID))
                {
                    c.texture = CustomShirtsMod.syncedHats[c.hatId + "." + who.UniqueMultiplayerID];
                }

                if (c.texture == null && !requestedHatSyncs.Contains(c.hatId + "." + who.UniqueMultiplayerID))
                {
                    requestedHatSyncs.Add(c.hatId + "." + who.UniqueMultiplayerID);
                    try
                    {
                        Task.Run(async() =>
                        {
                            await PyNet.sendRequestToFarmer <HatSync>(CustomShirtsMod.HatSyncerRequestName, c.hatId, who, (hs) =>
                            {
                                requestedHatSyncs.Remove(c.hatId + "." + who.UniqueMultiplayerID);

                                if (hs == null || hs.Texture == null)
                                {
                                    return;
                                }

                                if (CustomShirtsMod.syncedHats.ContainsKey(hs.SyncId))
                                {
                                    CustomShirtsMod.syncedHats.Remove(hs.SyncId);
                                }

                                CustomShirtsMod.syncedHats.Add(hs.SyncId, hs.Texture.getTexture());
                            }, SerializationType.PLAIN, 1000);
                        });
                    }
                    catch (Exception e)
                    {
                        CustomShirtsMod._monitor.Log(e.Message + ":" + e.StackTrace);
                    }
                }

                if (c.texture != null)
                {
                    int direction = who.FacingDirection;
                    FarmerRenderer.hatsTexture = c.texture;
                    if (direction == 0)
                    {
                        direction = 3;
                    }
                    else if (direction == 2)
                    {
                        direction = 0;
                    }
                    else if (direction == 3)
                    {
                        direction = 2;
                    }

                    if (Game1.activeClickableMenu is TitleMenu || Game1.activeClickableMenu is GameMenu)
                    {
                        direction = 0;
                    }

                    if (c.texture is ScaledTexture2D sct)
                    {
                        sct.ForcedSourceRectangle = new Rectangle(0, (int)(direction * 20 * sct.Scale), (int)(20 * sct.Scale), (int)(20 * sct.Scale));
                    }
                }
            }
            else
            {
                FarmerRenderer.hatsTexture = CustomShirtsMod.vanillaHats;
            }

            bool savedShirt = CustomShirtsMod.playerShirts.ContainsKey(who.UniqueMultiplayerID) && CustomShirtsMod.playerBaseShirts.ContainsKey(who.UniqueMultiplayerID) && CustomShirtsMod.playerBaseShirts[who.UniqueMultiplayerID] != -9999;

            if (savedShirt && (Game1.activeClickableMenu is CharacterCustomization || menuIsCC()))
            {
                savedShirt = false;
                CustomShirtsMod.playerShirts.Remove(who.UniqueMultiplayerID);
                CustomShirtsMod.playerBaseShirts.Remove(who.UniqueMultiplayerID);
                who.shirt.Value = ((CustomShirtsMod.shirts.FindIndex(fj => fj.fullid == CustomShirtsMod.config.ShirtId) + 1) * -1);
            }

            if (who.shirt.Value >= 0 && !savedShirt)
            {
                FarmerRenderer.shirtsTexture = CustomShirtsMod.vanillaShirts;
                return;
            }
            else
            {
                try
                {
                    if (!savedShirt && who == Game1.player)
                    {
                        FarmerRenderer.shirtsTexture = CustomShirtsMod.shirts[(who.shirt.Value * -1) - 1].texture2d;
                    }
                    else
                    {
                        if (CustomShirtsMod.playerShirts[who.UniqueMultiplayerID] == null)
                        {
                            return;
                        }
                        FarmerRenderer.shirtsTexture = CustomShirtsMod.playerShirts[who.UniqueMultiplayerID];
                    }
                }
                catch { }
            }

            if (FarmerRenderer.shirtsTexture is ScaledTexture2D st)
            {
                st.ForcedSourceRectangle = new Rectangle?(new Rectangle(0, (int)((facingDirection == 0 ? 24 : facingDirection == 1 ? 8 : facingDirection == 3 ? 16 : 0) * st.Scale), (int)(8 * st.Scale), (int)(8 * st.Scale)));
            }
        }