Beispiel #1
0
        public override void OnNPCDoJob(ref NPCBase.NPCState state)
        {
            base.OnNPCDoJob(ref state);

            if (state.JobIsDone == true)
            {
                Data.NPCData d = Managers.NPCManager.getNPCData(this.usedNPC.ID, this.owner);
                d.XPData.addXP(this.usedNPC.ID, jobtype, this.owner);
                Managers.NPCManager.updateNPCData(this.usedNPC.ID, d);
            }
        }
Beispiel #2
0
 public static Data.NPCData getNPCData(int id, Players.Player owner)
 {
     if (NPCDataList.ContainsKey(id))
     {
         return(NPCDataList[id]);
     }
     else
     {
         Data.NPCData d = new Data.NPCData(owner);
         NPCDataList.Add(id, d);
         return(d);
     }
 }
Beispiel #3
0
        public static void saveNPCData()
        {
            try
            {
                string jSONPath = GetJSONPath();
                Utilities.MakeDirectoriesIfNeeded(jSONPath);
                if (NPCDataList.Count == 0)
                {
                    File.Delete(jSONPath);
                }
                else
                {
                    // make a JSON node
                    JSONNode rootnode = new JSONNode(NodeType.Array);

                    // then go through stuff
                    foreach (int npcID in NPCDataList.Keys)
                    {
                        Data.NPCData npcData = NPCDataList[npcID];

                        // build a child node
                        JSONNode child = new JSONNode(NodeType.Object);

                        // Create the JSON
                        child.SetAs("id", npcID);
                        child.SetAs("owner", npcData.owner.ID.steamID);
                        child.SetAs("xpdata", npcData.XPData.toJSON());
                        child.SetAs("name", npcData.name);

                        rootnode.AddToArray(child);
                    }

                    Pipliz.JSON.JSON.Serialize(jSONPath, rootnode);
                }
            }
            catch (Exception exception2)
            {
                Utilities.WriteLog("Exception in saving all NPC Data:" + exception2.Message);
            }
        }
Beispiel #4
0
        override protected bool RunCommand(Players.Player player, string[] args, NetworkID target)
        {
            ColonyAPI.Helpers.Utilities.WriteLog("ColonyPlusPlus", "NPC Command Called");
            if (PermissionsManager.CheckAndWarnPermission(player, "npc.info"))
            {
                if (args.Length == 1)
                {
                    int npcID = 0;
                    int.TryParse(args[0], out npcID);

                    if (Managers.NPCManager.npcExists(npcID))
                    {
                        Data.NPCData npcD = Managers.NPCManager.getNPCData(npcID, player);

                        if (npcD.owner == player || PermissionsManager.HasPermission(player, "npc.admin"))
                        {
                            // is their NPC or is admin
                            ColonyAPI.Helpers.Chat.sendSilent(player, "NPC Info for: " + npcD.name + " (ID: " + npcID + ")", ColonyAPI.Helpers.Chat.ChatColour.cyan);
                            ColonyAPI.Helpers.Chat.sendSilent(player, "Levels:", ColonyAPI.Helpers.Chat.ChatColour.cyan);
                            foreach (string job in npcD.XPData.XPLevels.Keys)
                            {
                                ColonyAPI.Helpers.Chat.sendSilent(player, String.Format("{0}: {1} ({2}/{3} XP)", job, npcD.XPData.XPLevels[job], npcD.XPData.getRawXP(job), npcD.XPData.getXPForNextLevel(npcD.XPData.XPLevels[job])), ColonyAPI.Helpers.Chat.ChatColour.cyan);
                            }
                        }
                    }
                }
                else
                {
                    ColonyAPI.Helpers.Chat.sendSilent(player, "Invalid arguments. Usage:", ColonyAPI.Helpers.Chat.ChatColour.orange);
                    ColonyAPI.Helpers.Chat.sendSilent(player, "/npc info <id> - get info on an NPC of ID 'id'", ColonyAPI.Helpers.Chat.ChatColour.orange);
                }
                return(true);
            }
            else
            {
                ColonyAPI.Helpers.Chat.sendSilent(player, "You are unable to use NPC commands", ColonyAPI.Helpers.Chat.ChatColour.yellow);
                return(false);
            }
        }
Beispiel #5
0
 private void AddXP()
 {
     Data.NPCData d = Managers.NPCManager.getNPCData(this.usedNPC.ID, this.owner);
     d.XPData.addXP(this.usedNPC.ID, jobtype, this.owner);
     Managers.NPCManager.updateNPCData(this.usedNPC.ID, d);
 }
Beispiel #6
0
        public static void loadNPCData()
        {
            try
            {
                JSONNode array;
                if (Pipliz.JSON.JSON.Deserialize(GetJSONPath(), out array, false))
                {
                    if (array != null)
                    {
                        foreach (JSONNode node in array.LoopArray())
                        {
                            try
                            {
                                int            npcID = node["id"].GetAs <int>();
                                Players.Player owner = Players.GetPlayer(new NetworkID(new CSteamID(node["owner"].GetAs <ulong>())));


                                //Utilities.WriteLog("Loaded NPC: " + npcID);

                                if (!NPCDataList.ContainsKey(npcID))
                                {
                                    // doesn't exist, add it!
                                    Data.NPCData npcData = new Data.NPCData(owner);

                                    JSONNode xpdata = node["xpdata"].GetAs <JSONNode>();

                                    if (xpdata.ChildCount > 0)
                                    {
                                        foreach (KeyValuePair <string, JSONNode> current in xpdata.LoopObject())
                                        {
                                            npcData.XPData.setXP(current.Key, current.Value.GetAs <ushort>());
                                            //Utilities.WriteLog("Added XP: " + current.Key + " value: " + current.Value.GetAs<ushort>());
                                        }
                                    }
                                    npcData.XPData.recalculateAllLevels();

                                    string npcName = node["name"].GetAs <string>();
                                    npcData.name = npcName;

                                    NPCDataList.Add(npcID, npcData);
                                }
                            }
                            catch (Exception exception)
                            {
                                Utilities.WriteLog("Exception loading NPC data;" + exception.Message);
                            }
                        }

                        Utilities.WriteLog("Loaded NPCData");
                    }
                    else
                    {
                        Utilities.WriteLog("Loading NPC data returned 0 results");
                    }
                }
                else
                {
                    Utilities.WriteLog("Found no NPC Data (read error?)");
                }
            }
            catch (Exception exception2)
            {
                Utilities.WriteLog("Exception in loading NPC data:" + exception2.Message);
            }
        }
Beispiel #7
0
 public static void updateNPCData(int id, Data.NPCData d)
 {
     NPCDataList[id] = d;
 }