void OnReady(NetworkMessage netMsg)
    {
        NetArray netArray = netMsg.ReadMessage <NetArray>();

        netArray.value = netArray.value.Except(ConnectedUsers.Select(x => x.id)).ToArray();
        NetworkServer.SendToClient(netMsg.conn.connectionId, 791, netArray);
    }
Example #2
0
 private static void RestorePlayerExperience(NetArray <int, NetInt> snapshotPlayerExperience)
 {
     for (int i = 0; i < Game1.player.experiencePoints.Length; i++)
     {
         Game1.player.experiencePoints[i] = snapshotPlayerExperience[i];
     }
 }
Example #3
0
        private void SetTexture()
        {
            //
            //  load the text for the selected Bubble type
            //
            _bThoughtLoaded = _IsThought.Value;

            lock (oBackground)
            {
                if (_IsThought.Value)
                {
                    sbBackground = new StardewBitmap(Path.Combine(ModPath, "think_bubble.png"));
                }
                else
                {
                    sbBackground = new StardewBitmap(Path.Combine(ModPath, "talk_bubble.png"));
                }

                sbBackground.ResizeImage(300, 200);
                if (Game1.IsMultiplayer)
                {
                    //
                    //  store image data to send to other players
                    //
                    _BubbleImageData = sbBackground.TextureNetArray();
                }
            }
        }
Example #4
0
 public void SetBundleData(Dictionary <string, string> data)
 {
     _bundleDataDirty = true;
     netBundleData.CopyFrom(data);
     foreach (string key in netBundleData.Keys)
     {
         string value = netBundleData[key];
         int    index = Convert.ToInt32(key.Split('/')[1]);
         int    count = value.Split('/')[2].Split(' ').Length;
         if (!bundles.ContainsKey(index))
         {
             bundles.Add(index, new NetArray <bool, NetBool>(count));
         }
         else if (bundles[index].Length < count)
         {
             NetArray <bool, NetBool> new_array = new NetArray <bool, NetBool>(count);
             for (int i = 0; i < Math.Min(bundles[index].Length, count); i++)
             {
                 new_array[i] = bundles[index][i];
             }
             bundles.Remove(index);
             bundles.Add(index, new_array);
         }
         if (!bundleRewards.ContainsKey(index))
         {
             bundleRewards.Add(index, new NetBool(value: false));
         }
     }
 }
Example #5
0
 private void hookArray(NetArray <TValue, NetRef <TValue> > array)
 {
     for (int index = 0; index < array.Count; ++index)
     {
         this.hookField(index, array.Fields[index]);
     }
     //this.innerArray.OnFieldCreate += new NetArray<TValue, NetRef<TValue>>.FieldCreateEvent(this.hookField);
 }
Example #6
0
    void OnReadyReply(NetworkMessage netMsg)
    {
        NetArray oldPlayers = netMsg.ReadMessage <NetArray>();

        foreach (int c in oldPlayers.value)
        {
            playerDisconnect(c);
        }
    }
Example #7
0
        private void SaveEvents_AfterLoad(object sender, EventArgs e)
        {
            config = instance.Helper.Data.ReadJsonFile <ModData>($"Data/{Constants.SaveFolderName}.json") ?? new ModData();

            sanity = config.sanity;

            oXP     = Game1.player.experiencePoints;
            oHealth = Game1.player.health;
            oSpeed  = Game1.player.addedSpeed;
        }
Example #8
0
        public void FillArray(ref NetArray <int, NetInt> oArray)
        {
            oArray.Clear();
            MemoryStream ms = StardewThreadSafeLoader.GetTextureMS("FillArray", Texture());

            //Texture().SaveAsPng(ms, SourceImage.Width, SourceImage.Height);
            foreach (byte bBtyte in ms.ToArray())
            {
                oArray.Add(bBtyte);
            }
        }
Example #9
0
        private bool DoTrashLoot(string value)
        {
            var  lootTable = new List <TrashLootEntry>();
            bool hasFilter = int.TryParse(value.Split(' ')[1], out int which);

            if (!hasFilter)
            {
                return(false);
            }
            StardewValley.Locations.Town t = (StardewValley.Locations.Town)Game1.getLocationFromName("Town");

            //was this can already checked today?
            NetArray <bool, NetBool> wasCheckedArray = (NetArray <bool, NetBool>) typeof(StardewValley.Locations.Town).GetField("garbageChecked", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(t);

            if (wasCheckedArray[which])
            {
                return(false);
            }

            //build a loot table specific to this can, as provided by mods
            foreach (var l in API.Items.TrashLoot)
            {
                if (l.Filter == -1)
                {
                    lootTable.Add(l);                 //"any can" item
                }
                else if (l.Filter == which)
                {
                    lootTable.Add(l);
                }
            }

            if (lootTable.Count > 0 && Modworks.RNG.NextDouble() < (System.Math.Min(0.1d + Modworks.Player.GetLuckFactorFloat(), 0.9d)))  //10% to 90% chance, influenced by luck
            {
                TrashLootEntry tle    = lootTable[Modworks.RNG.Next(lootTable.Count)];
                int?           itemId = Modworks.Items.GetModItemId(tle.Module, tle.ItemID);
                if (!itemId.HasValue)
                {
                    Modworks.Log.Debug("Attempted to award trash item of invalid id: " + tle.ItemID);
                    return(false);
                }
                Modworks.Player.GiveItem(itemId.Value);
                Game1.playSound("trashcan");
                wasCheckedArray[which] = true; //mark the can as checked
                return(true);
            }
            return(false);
        }
Example #10
0
    //server reply methods

    void OnWelcome(NetworkMessage netMsg)
    {
        Welcome welcome = netMsg.ReadMessage <Welcome>();

        spawnPlayer(welcome.position);
        id = welcome.id;

        foreach (User u in welcome.users)
        {
            GameObject enemy = GameObject.Instantiate(Resources.Load <GameObject>("Prefabs/enemy"), u.position, u.rotation);
            enemy.transform.Find("username").GetComponent <TextMesh>().text = u.username;
            enemy.name = "e" + u.id;
            enemy.GetComponent <enemy>().setId(u.id);
            enemy.GetComponent <enemy>().setMedia(u.media);
            enemy.GetComponent <enemy>().setKills(u.kills);
            players.Add(u.id, enemy);
            if (u.dead)
            {
                enemy.transform.localScale = new Vector3(0, 0, 0);
            }
            if (u.kills > maxPoints)
            {
                setRecordHolder(u.id, u.kills);
            }
        }

        nm.nc.RegisterHandler(791, OnReadyReply);
        nm.nc.RegisterHandler(810, OnEnemyDisconnect);
        nm.nc.RegisterHandler(898, OnEnemyUpdate);
        nm.nc.RegisterHandler(910, OnEnemyRotChange);
        nm.nc.RegisterHandler(911, OnEnemyPosCorrection);
        nm.nc.RegisterHandler(912, OnEnemyDirChange);
        nm.nc.RegisterHandler(917, OnEnemyArmRotate);
        nm.nc.RegisterHandler(913, OnEnemyShoot);
        nm.nc.RegisterHandler(914, OnEnemyDied);
        nm.nc.RegisterHandler(915, OnDamage);
        nm.nc.RegisterHandler(916, OnEnemyRespawn);
        nm.nc.RegisterHandler(918, OnEnemyJump);
        nm.nc.RegisterHandler(926, OnPlayerRespawn);


        NetArray na = new NetArray();

        na.value = players.Keys.ToArray();
        nm.nc.Send(790, na);
    }
Example #11
0
        public NetArray <int, NetInt> TextureNetArray()
        {
            //
            //  probably not the most efficient method but it
            //  provides the ability to passs textures between
            //  multiplayer players
            //
            NetArray <int, NetInt> arReturn = new NetArray <int, NetInt>();
            MemoryStream           ms       = new MemoryStream();

            Texture().SaveAsPng(ms, SourceImage.Width, SourceImage.Height);
            foreach (byte bBtyte in ms.ToArray())
            {
                arReturn.Add(bBtyte);
            }

            return(arReturn);
        }
Example #12
0
        public StardewBitmap(NetArray <int, NetInt> oNetArray)
        {
            //
            //  real fun hack to be able to pass bubble images
            //  between players
            //
            int[] arBytes = new int[oNetArray.Count];
            oNetArray.CopyTo(arBytes, 0);
            byte[] result = new byte[arBytes.Length];
            for (int iPtr = 0; iPtr < arBytes.Length; iPtr++)
            {
                result[iPtr] = (byte)arBytes[iPtr];
            }

            MemoryStream ms = new MemoryStream(result, false);

            ms.Seek(0, SeekOrigin.Begin);
            SourceImage = SKBitmap.Decode(ms);
        }
Example #13
0
        private void SetTexture()
        {
            _bThoughtLoaded = _IsThought.Value;

            lock (oBackground)
            {
                if (_IsThought.Value)
                {
                    sbBackground = new StardewBitmap(Path.Combine(ModPath, "think_bubble.png"));
                }
                else
                {
                    sbBackground = new StardewBitmap(Path.Combine(ModPath, "talk_bubble.png"));
                }
                sbBackground.ResizeImage(300, 200);
                _BubbleImageData = sbBackground.TextureNetArray();

                //sbBackground.Save("bubbleguy.png");
            }
        }
        public static void Utility_isThereAFarmerOrCharacterWithinDistance_postfix(ref Character __result, Vector2 tileLocation, int tilesAway, GameLocation environment)
        {
            if (!Config.Enabled || __result == null || !(__result is NPC) || __result is Horse || !(environment is Town) || !Config.SpecificCharacters.ContainsKey(__result.name))
            {
                return;
            }
            string s        = environment.doesTileHaveProperty((int)tileLocation.X, (int)tileLocation.Y, "Action", "Buildings");
            int    whichCan = (s != null) ? Convert.ToInt32(s.Split(' ')[1]) : -1;
            NetArray <bool, NetBool> garbageChecked = PHelper.Reflection.GetField <NetArray <bool, NetBool> >(environment, "garbageChecked").GetValue();

            if (whichCan >= 0 && whichCan < garbageChecked.Length)
            {
                PMonitor.Log($"trash voyer");
                Reactor r = Config.SpecificCharacters[__result.name];
                __result.doEmote(r.emote, true);
                (__result as NPC).setNewDialogue(Game1.content.LoadString(r.dialogue), true, true);
                Game1.player.changeFriendship(r.points, __result as NPC);
                Game1.drawDialogue(__result as NPC);
                __result = null;
            }
        }
Example #15
0
 protected override void setFieldValue(NetArray <int, NetInt> field, int key, int[] value)
 {
     field.Set(value);
 }
        private static void FindAllInstances(object value, List <string> propNames, HashSet <object> exploredObjects, Dictionary <object, List <object> > found, object parent)
        {
            if (value == null || exploredObjects.Contains(value))
            {
                return;
            }

            exploredObjects.Add(value);
            IDictionary dict = value as IDictionary;
            IList       list = value as IList;
            ICollection col  = value as ICollection;
            OverlaidDictionary <Vector2, SObject> ovd            = value as OverlaidDictionary <Vector2, SObject>;
            NetObjectList <Item>     noli                        = value as NetObjectList <Item>;
            NetCollection <Building> netBuildings                = value as NetCollection <Building>;
            NetArray <SObject, NetRef <SObject> > netObjectArray = value as NetArray <SObject, NetRef <SObject> >;


            if (dict != null)
            {
                foreach (object item in dict.Values)
                {
                    FindAllInstances(item, propNames, exploredObjects, found, dict);
                }
            }
            else if (list != null)
            {
                foreach (object item in list)
                {
                    FindAllInstances(item, propNames, exploredObjects, found, list);
                }
            }
            else if (col != null)
            {
                foreach (object item in col)
                {
                    FindAllInstances(item, propNames, exploredObjects, found, col);
                }
            }
            else if (ovd != null)
            {
                foreach (object item in ovd.Values)
                {
                    FindAllInstances(item, propNames, exploredObjects, found, ovd);
                }
            }
            else if (noli != null)
            {
                foreach (object item in noli)
                {
                    FindAllInstances(item, propNames, exploredObjects, found, noli);
                }
            }
            else if (netBuildings != null)
            {
                foreach (object item in netBuildings)
                {
                    FindAllInstances(item, propNames, exploredObjects, found, netBuildings);
                }
            }
            else if (netObjectArray != null)
            {
                foreach (SObject item in netObjectArray.Where(no => no != null))
                {
                    FindAllInstances(item, propNames, exploredObjects, found, netObjectArray);
                }
            }
            else
            {
                if (found.ContainsKey(parent))
                {
                    found[parent].Add(value);
                }
                else
                {
                    found.Add(parent, new List <object>()
                    {
                        value
                    });
                }

                Type type = value.GetType();

                FieldInfo[] fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.GetProperty);

                foreach (FieldInfo field in fields)
                {
                    if (!propNames.Contains(field.Name))
                    {
                        continue;
                    }

                    object propertyValue = field.GetValue(value);
                    if (propertyValue != null && propertyValue.GetType() is Type t && t.IsClass)
                    {
                        FindAllInstances(propertyValue, propNames, exploredObjects, found, new KeyValuePair <FieldInfo, object>(field, value));
                    }
                }
            }
        }
        private static void CollectTrashCan(int x, int y)
        {
            if (!(Game1.currentLocation is Town town))
            {
                return;
            }

            NetArray <bool, NetBool> garbageChecked =
                Reflection.GetField <NetArray <bool, NetBool> >(town, "garbageChecked").GetValue();

            string text = Game1.currentLocation.doesTileHaveProperty(x, y, "Action", "Buildings");
            int    num  = text != null?Convert.ToInt32(text.Split(' ')[1]) : -1;

            if (num >= 0 && num < garbageChecked.Length && !garbageChecked[num])
            {
                garbageChecked[num] = true;
                Game1.currentLocation.playSound("trashcan");
                Random random = new Random((int)Game1.uniqueIDForThisGame / 2 + (int)Game1.stats.DaysPlayed + 777 + num);
                if (random.NextDouble() < 0.2 + Game1.player.DailyLuck)
                {
                    int parentSheetIndex = 168;
                    switch (random.Next(10))
                    {
                    case 0:
                        parentSheetIndex = 168;
                        break;

                    case 1:
                        parentSheetIndex = 167;
                        break;

                    case 2:
                        parentSheetIndex = 170;
                        break;

                    case 3:
                        parentSheetIndex = 171;
                        break;

                    case 4:
                        parentSheetIndex = 172;
                        break;

                    case 5:
                        parentSheetIndex = 216;
                        break;

                    case 6:
                        parentSheetIndex = Utility.getRandomItemFromSeason(Game1.currentSeason, x * 653 + y * 777, false);
                        break;

                    case 7:
                        parentSheetIndex = 403;
                        break;

                    case 8:
                        parentSheetIndex = 309 + random.Next(3);
                        break;

                    case 9:
                        parentSheetIndex = 153;
                        break;
                    }
                    switch (num)
                    {
                    case 3 when random.NextDouble() < 0.2 + Game1.player.DailyLuck:
                        parentSheetIndex = 535;

                        if (random.NextDouble() < 0.05)
                        {
                            parentSheetIndex = 749;
                        }

                        break;

                    case 4 when random.NextDouble() < 0.2 + Game1.player.DailyLuck:
                        parentSheetIndex = 378 + random.Next(3) * 2;

                        break;

                    case 5 when random.NextDouble() < 0.2 + Game1.player.DailyLuck && Game1.dishOfTheDay != null:
                        parentSheetIndex = Game1.dishOfTheDay.ParentSheetIndex != 217 ? Game1.dishOfTheDay.ParentSheetIndex : 216;

                        break;

                    case 6 when random.NextDouble() < 0.2 + Game1.player.DailyLuck:
                        parentSheetIndex = 223;

                        break;
                    }

                    Logger.Log($"You picked up trash @ [{x},{y}]");
                    Game1.player.addItemByMenuIfNecessary(new Object(parentSheetIndex, 1));
                }
            }
        }
Example #18
0
 protected override bool[] getFieldTargetValue(NetArray <bool, NetBool> field)
 {
     return(field.ToArray());
 }
Example #19
0
 protected override void setFieldValue(NetArray <bool, NetBool> field, int key, bool[] value)
 {
     field.Set(value);
 }
Example #20
0
 protected override int[] getFieldTargetValue(NetArray <int, NetInt> field)
 {
     return(field.ToArray());
 }
Example #21
0
        private double getSanityChange()
        {
            double s = 0.0;

            for (int i = 0; i < Game1.player.experiencePoints.Count - 1; i++)
            {
                if (oXP[i] != Game1.player.experiencePoints[i])
                {
                    switch (i)
                    {
                    case 0:
                        s += 0.5;
                        break;

                    case 1:
                        s += 0.3;
                        break;

                    case 2:
                        s += 0.4;
                        break;

                    case 3:
                        s -= 0.1;
                        break;

                    case 4:
                        s -= 0.5;
                        break;

                    default:
                        break;
                    }
                }

                oXP = Game1.player.experiencePoints;
            }

            if (Game1.isDarkOut())
            {
                s -= 0.3;
            }
            if (Game1.isRaining && Game1.player.currentLocation.IsOutdoors)
            {
                s -= 0.1;
            }
            if (Game1.currentLocation is MineShaft)
            {
                s -= 0.2;
            }
            if (Game1.isLightning && Game1.player.currentLocation.IsOutdoors)
            {
                s -= 0.5;
            }

            bool alone = true;

            foreach (Farmer f in Game1.getOnlineFarmers())
            {
                if (Game1.player.currentLocation == f.currentLocation && Vector2.Distance(Game1.player.getTileLocation(), f.getTileLocation()) <= 20.0f)
                {
                    s += 0.3;

                    alone = false;
                }
            }
            foreach (NPC f in Game1.currentLocation.characters)
            {
                if (Vector2.Distance(Game1.player.getTileLocation(), f.getTileLocation()) <= 10.0f && !(f is Monster))
                {
                    s += 0.2;

                    alone = false;
                }
                else if (Vector2.Distance(Game1.player.getTileLocation(), f.getTileLocation()) <= 10.0f && (f is Monster) && (f as Monster).wildernessFarmMonster)
                {
                    s -= 0.2;
                }
            }

            if (alone)
            {
                s -= 0.2;
            }
            if (Game1.player.isEating)
            {
                s += 0.5;
            }
            if (Game1.player.isDivorced())
            {
                s -= 0.2;
            }
            if (Game1.player.isEngaged())
            {
                s += 0.2;
            }
            if (Game1.player.isInBed.Value)
            {
                s += 0.2;
            }
            if (Game1.player.isMoving())
            {
                s -= 0.1;
            }
            if (Game1.player.Stamina <= (Game1.player.Stamina / 4.0f))
            {
                s -= 0.5;
            }
            if (Game1.player.health <= (Game1.player.health / 4.0f))
            {
                s -= 0.5;
            }
            if (Game1.player.hasPet())
            {
                s += 0.2;
            }
            if (Game1.player.hasUnlockedSkullDoor)
            {
                s -= 0.5;
            }

            foreach (Item i in Game1.player.Items)
            {
                if (i == null)
                {
                }

                else if (i.Category == StardewValley.Object.flowersCategory || i.Category == StardewValley.Object.GemCategory || i.Category == StardewValley.Object.diamondIndex)
                {
                    s += 0.1;
                }
                else if (i.Category == StardewValley.Object.iridiumBar)
                {
                    s += 0.5;
                }
                else if (i.Category == StardewValley.Object.stardrop && Game1.player.CurrentItem.Name.ToLower().Contains("stardrop"))
                {
                    s += 1.0;
                }
                else if (i.Category == StardewValley.Object.monsterLootCategory)
                {
                    s -= 0.2;
                }
            }

            if (Game1.player.addedSpeed < 0)
            {
                s -= 0.2;
            }

            if (oHealth - Game1.player.health > 0)
            {
                s -= 0.4;
            }

            oHealth = Game1.player.health;

            foreach (NPC npc in Utility.getAllCharacters())
            {
                if (Game1.player.getFriendshipHeartLevelForNPC(npc.Name) >= 5)
                {
                    s += 0.1;
                }
            }

            if (!Game1.player.currentLocation.IsOutdoors)
            {
                s += 0.3;
            }
            if (Game1.activeClickableMenu != null && Game1.activeClickableMenu is BobberBar)
            {
                s += 0.2;
            }
            if (sanity <= 30.0)
            {
                s -= 0.4;
            }
            if (sanity <= 50.0 && sanity > 30.0)
            {
                s -= 0.2;
            }

            return(s);
        }
Example #22
0
        private static void FindAllInstances(object value, List <string> propNames, HashSet <object> exploredObjects, Dictionary <object, List <object> > found, object parent)
        {
            if (value == null || exploredObjects.Contains(value))
            {
                return;
            }

            exploredObjects.Add(value);
            IDictionary                           dict           = value as IDictionary;
            IList                                 list           = value as IList;
            ICollection                           col            = value as ICollection;
            OverlaidDictionary                    ovd            = value as OverlaidDictionary;
            NetObjectList <Item>                  noli           = value as NetObjectList <Item>;
            NetCollection <Building>              netBuildings   = value as NetCollection <Building>;
            NetCollection <Furniture>             netFurniture   = value as NetCollection <Furniture>;
            NetArray <SObject, NetRef <SObject> > netObjectArray = value as NetArray <SObject, NetRef <SObject> >;
            NetVector2Dictionary <TerrainFeature, NetRef <TerrainFeature> > terrain = value as NetVector2Dictionary <TerrainFeature, NetRef <TerrainFeature> >;

            if (dict != null)
            {
                foreach (object item in dict.Keys)
                {
                    if (dict[item] != null)
                    {
                        FindAllInstances(dict[item], propNames, exploredObjects, found, new KeyValuePair <IDictionary, object>(dict, item));
                    }
                }
            }
            else if (list != null)
            {
                foreach (object item in list)
                {
                    FindAllInstances(item, propNames, exploredObjects, found, list);
                }
            }
            else if (col != null)
            {
                foreach (object item in col)
                {
                    FindAllInstances(item, propNames, exploredObjects, found, col);
                }
            }
            else if (ovd != null)
            {
                foreach (Vector2 item in ovd.Keys)
                {
                    if (ovd[item] != null)
                    {
                        FindAllInstances(ovd[item], propNames, exploredObjects, found, new KeyValuePair <OverlaidDictionary, object>(ovd, item));
                    }
                    FindAllInstances(item, propNames, exploredObjects, found, ovd);
                }
            }
            else if (noli != null)
            {
                foreach (object item in noli)
                {
                    FindAllInstances(item, propNames, exploredObjects, found, noli);
                }
            }
            else if (netBuildings != null)
            {
                foreach (object item in netBuildings)
                {
                    FindAllInstances(item, propNames, exploredObjects, found, netBuildings);
                }
            }
            else if (netFurniture != null)
            {
                foreach (object item in netFurniture)
                {
                    FindAllInstances(item, propNames, exploredObjects, found, netFurniture);
                }
            }
            else if (netObjectArray != null)
            {
                foreach (SObject item in netObjectArray.Where(no => no != null))
                {
                    FindAllInstances(item, propNames, exploredObjects, found, netObjectArray);
                }
            }
            else if (terrain != null)
            {
                var fd = terrain.FieldDict;
                foreach (var item in terrain.Keys.Where(v => terrain[v] != null && terrain[v] is ISaveElement || getDataString(terrain[v]).StartsWith(newPrefix)))
                {
                    FindAllInstances(fd[item], propNames, exploredObjects, found, new KeyValuePair <IDictionary, object>(fd, item));
                }
            }
            else
            {
                if (found.ContainsKey(parent))
                {
                    found[parent].Add(value);
                }
                else
                {
                    found.Add(parent, new List <object>()
                    {
                        value
                    });
                }

                Type type = value.GetType();

                FieldInfo[] fields;

                if (fieldInfoChache.ContainsKey(type))
                {
                    fields = fieldInfoChache[type];
                }
                else
                {
                    fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
                    fieldInfoChache.Add(type, fields);
                }

                foreach (FieldInfo field in fields.Where(f => propNames.Contains(f.Name)))
                {
                    object propertyValue = field.GetValue(value);
                    if (propertyValue != null && propertyValue.GetType() is Type ty && ty.IsClass)
                    {
                        FindAllInstances(propertyValue, propNames, exploredObjects, found, new KeyValuePair <FieldInfo, object>(field, value));
                    }
                }
            }
        }