Exemplo n.º 1
0
        /*
         * When the Command is Dispatched
         */
        public static void CommandGeneticsBase(string command, string[] args)
        {
            // Get input length
            switch (args.Length)
            {
            case 0:
                ModEntry.MONITOR.Log("Must specify a <gender> and an <NPC>.", LogLevel.Error);
                return;

            case 1:
            case 2: {
                // Get the inputted child
                Child child = ChildDat.GetByName(args[0]);

                if (/* Child must be an existing Child */ child == null)
                {
                    ModEntry.MONITOR.Log($"Could not location a <Child> named \"{args[0]}\".", LogLevel.Error);
                }

                else if (/* Child cannot be another players */ child.idOfParent.Value != Game1.player.UniqueMultiplayerID && (!Context.IsMainPlayer))
                {
                    ModEntry.MONITOR.Log($"That <Child> \"{args[0]}\" does not belong to you.", LogLevel.Error);
                }

                else if (args.Length == 1)
                {
                    ModEntry.MONITOR.Log($"{child.Name}'s parent is {ChildDat.Of(child).ParentName}.", LogLevel.Info);
                }

                else
                {
                    // Get the inputted spouse
                    NPC parent = Game1.getCharacterFromName(args[1], true);
                    if (/* Parent must be an existing NPC */ parent == null)
                    {
                        ModEntry.MONITOR.Log($"Specified <Parent> \"{args[1]}\" could not be located.", LogLevel.Error);
                    }
                    else if (/* NPC must be an Adult NPC */ !Blender.IsOfAge(parent))
                    {
                        ModEntry.MONITOR.Log($"Specified <Parent> must be an adult!", LogLevel.Error);
                    }
                    else
                    {
                        ChildDat data = ChildDat.Of(child, parent);
                        if (!data.Save(true))
                        {
                            Game1.addHUDMessage(new HUDMessage("Host is not using mod \"NotFarFromTheTree\". Updated Children will not save.", HUDMessage.error_type));
                        }
                        ModEntry.MONITOR.Log($"{data.ChildName} now takes after {data.ParentName}", LogLevel.Info);
                    }
                }
                return;
            }

            default: {
                ModEntry.MONITOR.Log("Too many parameters.", LogLevel.Error);
                return;
            }
            }
        }
Exemplo n.º 2
0
        public static bool reloadSprite(Child __instance)
        {
            try {
                // Load the multiplayer IDs of Child Parents
                if (Game1.IsMasterGame)
                {
                    // Iterate farmers
                    Farmer farmer = Game1.getFarmerMaybeOffline(__instance.idOfParent.Value);
                    if (__instance.idOfParent.Value == 0L || farmer == null)
                    {
                        long multiplayerId = Game1.MasterPlayer.UniqueMultiplayerID;
                        if (__instance.currentLocation is FarmHouse)
                        {
                            foreach (Farmer allFarmer in Game1.getAllFarmers())
                            {
                                if (Utility.getHomeOfFarmer(allFarmer) == __instance.currentLocation)
                                {
                                    multiplayerId = allFarmer.UniqueMultiplayerID;
                                    break;
                                }
                            }
                        }

                        __instance.idOfParent.Value = multiplayerId;
                    }
                }

                ChildDat.Of(__instance)?.CleanSprite();
                return(false);
            } catch (Exception e) {
                ModEntry.MONITOR.Log($"Unexpected exception in {ModEntry.MOD_ID}:\n{e}", LogLevel.Error);
                return(true);
            }
        }
Exemplo n.º 3
0
        private bool saveChildParent(Child child, NPC parent, bool notify)
        {
            bool saveSuccess = false;

            ChildDat childDat = new ChildDat(child.getName(), parent.getName());
            string   saveKey  = this.getChildSaveKey(child);

            // Save the parent of the child
            this.childrenParent[saveKey] = childDat;
            if (Context.IsMainPlayer)
            {
                this.Helper.Data.WriteSaveData(saveKey, childDat);
                saveSuccess = true;
            }

            // Update other players in multiplayer
            if (Context.IsMultiplayer && notify)
            {
                if (this.sendToPeers(childDat))
                {
                    saveSuccess = true;
                }
            }

            return(saveSuccess);
        }
Exemplo n.º 4
0
        private bool loadChildsParent(Child child, out ChildDat data)
        {
            string key = this.getChildSaveKey(child);

            if (this.childrenParent.TryGetValue(key, out ChildDat cache))
            {
                // Attempt to read the value from the CACHE ARRAY
                return((
                           data = cache
                           ) != null);
            }
            else if (Context.IsMainPlayer)
            {
                // Player Must be the HOST to Read from Save Data
                // (Other players must be synced from the HOST to the CACHE ARRAY)
                return((
                           data = Helper.Data.ReadSaveData <ChildDat>(key)
                           ) != null);
            }
            else
            {
                data = null;
                return(false);
            }
        }
Exemplo n.º 5
0
        /*
         * Event Handlers
         */
        public static void OnMessageNotification(object sender, ModMessageReceivedEventArgs e)
        {
            if (e.FromModID != ModEntry.MOD_ID)
            {
                return;
            }

            switch (e.Type)
            {
            case "ChildUpdate": {
                ChildDat childDat = e.ReadAs <ChildDat>();
                childDat?.Save(Context.IsMainPlayer);
                break;
            }
            }
        }
Exemplo n.º 6
0
        private bool sendToPeers(ChildDat childDat)
        {
            bool sent = false;

            foreach (IMultiplayerPeer peer in this.Helper.Multiplayer.GetConnectedPlayers())
            {
                // If peer is the host, have them update the save
                if ((!Context.IsMainPlayer) && peer.IsHost && (peer.GetMod(this.ModManifest.UniqueID) != null))
                {
                    sent = true;
                }
                // Only send if host or to host
                if (Context.IsMainPlayer || (sent && peer.IsHost))
                {
                    this.Helper.Multiplayer.SendMessage(childDat, "ChildUpdate", modIDs: new[] {
                        this.ModManifest.UniqueID
                    });
                }
            }

            return(sent);
        }
Exemplo n.º 7
0
        /*
         * Event Handlers
         */
        private void OnMessageNotification(object sender, ModMessageReceivedEventArgs e)
        {
            if (e.FromModID == this.ModManifest.UniqueID && e.Type == "ChildUpdate")
            {
                ChildDat childDat = e.ReadAs <ChildDat>();
                Child    child    = getChildByName(childDat.child);
                NPC      parent   = Game1.getCharacterFromName <NPC>(childDat.parent, true);

                if (child != null)
                {
                    this.saveChildParent(
                        child,
                        parent,
                        Context.IsMainPlayer
                        );

                    if ((child.currentLocation != null) && child.currentLocation.Equals(Game1.currentLocation))
                    {
                        this.UpdateSprite(child, parent);
                    }
                }
            }
        }