예제 #1
0
        public override bool PreAI(NPC npc)
        {
            if (!KeepNames.blacklist.Contains(npc.type) &&
                (npc.townNPC || KeepNames.considerAsTownNPCs.Contains(npc.type)) &&
                GetInstance <nameConfigServer>().manualBlackList.FindIndex(b => b.Type == npc.type) == -1
                //exit if we are not either the host or in singleplayer
                && !(Main.netMode != Terraria.ID.NetmodeID.SinglePlayer && !Main.dedServ))
            {
                if (!KeepNames.patchedGame)
                {
                    int i = KeepNames.names.FindIndex(obj => obj.id == npc.type);
                    if (i != -1)
                    {
                        npc.GivenName = KeepNames.names[i].givenName;
                    }
                }
                else if (npc.GivenName != "")
                {
                    KeepNames.setName(npc.type, npc.GivenName);
                }
            }

            return(base.PreAI(npc));
        }
예제 #2
0
        /// <summary>
        /// Dynamically change listings and blacklists in KeepNames
        /// Returns true on success, false on fail
        /// Prints to log errors
        /// </summary>
        /// <example>Call( "blacklistNPC", NPCType<MyNPC>() );</example>
        /// <example>Call( "setName", NPCType<MyNPC>(), "MyNewName" );</example>
        /// <example>Call( "getSavedName", NPCType<MyNPC>() );</example>
        /// <param name="args">An object array of {"Method Name", [args in order]}</param>
        public override object Call(params object[] args)
        {
            if (args.Length < 2)
            {
                Logger.Error("Mod.Call() expects at least 2 arguments.");
                return(false);
            }
            try {
                string functionName = args[0] as string;
                switch (functionName)
                {
                case "blacklistNPC": {
                    int?id = args[1] as int?;
                    if (id == null)
                    {
                        Logger.Error("Second argument of blacklistNPC must be an int."); return(false);
                    }
                    blacklistNPC((int)id);
                    return(true);
                }

                case "setName": {
                    if (args.Length < 3)
                    {
                        Logger.Error("Mod.Call() expects at least 3 arguments."); return(false);
                    }
                    int?id = args[1] as int?;
                    if (id == null)
                    {
                        Logger.Error("Second argument of setName must be an int."); return(false);
                    }
                    string name = args[2] as string;
                    if (name == null)
                    {
                        Logger.Error("Third argument of setName must be a string."); return(false);
                    }
                    setName((int)id, name);
                    return(true);
                }

                case "getSavedName": {
                    int?id = args[1] as int?;
                    if (id == null)
                    {
                        Logger.Error("Second argument of getSavedName must be an int."); return(false);
                    }
                    _ = KeepNames.getSavedName((int)id);
                    return(true);
                }

                case "useNPC": {
                    int?id = args[1] as int?;
                    if (id == null)
                    {
                        Logger.Error("Second argument of useNPC must be an int."); return(false);
                    }
                    useNPC((int)id);
                    return(true);
                }

                default:
                    Logger.Warn($"Call Warning: Unknown method name '{functionName}'");
                    return(false);
                }
            }
            catch (Exception e) {
                Logger.Error($"Call Error: {e.StackTrace} {e.Message}");
                return(false);
            }
        }