Ejemplo n.º 1
0
        private int worldTime; //what time it is according to the world's clock

        #endregion Fields

        #region Constructors

        //private bool isDead = false; //you don't wanna be this, you're dead HAH!
        //private bool isFleeing = false;
        public Player(TcpClient client, ref ObservableCollection<Player> playerlist, Dictionary<string, Room> roomlist, ref List<NPC> npcs, System.Timers.Timer timer, int time, ref List<Item> itemlist, ref List<Item> expirableItemList, SkillTree _universalSkillTree)
        {
            //assign a bunch of stuff that's passed in from the server then the Player is created in memory
            this.tcpClient = client;
            this.name = null;
            this.players = playerlist;

            this.rooms = roomlist;
            this.npcs = npcs;
            this.itemList = itemlist;

            //the universal skill tree that lists all skills that can be learned along with each skill's effects etc.
            this.universalSkillTree = _universalSkillTree;

            //timer stuff for saving player data at set intervals
            this.savePlayerTimer = new System.Timers.Timer();
            this.savePlayerTimer.Interval = 300000;

            //assign handler to savePlayerTimer so player data will be saved every xx minutes
            this.savePlayerTimer.Elapsed += new ElapsedEventHandler(savePlayerTimer_Elapsed);

            this.savePlayerTimer.Enabled = true;
            this.savePlayerTimer.Start();

            //setting the time equal to the world time passed in from the server.
            this.worldTime = time;

            //if the time that's initially passed in is before 6 AM or after 9 PM (21:00), it's night time
            //which means it's dark, so players can't see without a light UNLESS they are in a lighted room
            //TODO: something wrong with timing, fix this
            if (this.worldTime < 6 || this.worldTime > 21)
            {
                isNight = true;
            }

            this.expirableItemList = expirableItemList;
        }
Ejemplo n.º 2
0
        public Server()
        {
            this.tcpListener = new TcpListener(IPAddress.Parse("0.0.0.0"), 3000);
            this.listenThread = new Thread(new ThreadStart(ListenForClients));
            this.listenThread.Start();

            this.worldTimer = new System.Timers.Timer();
            this.worldTimer.Interval = 100;

            this.worldTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);

            this.worldTimer.Enabled = true;

            this.time = 0;
            this.hour = 0;

            //TODO: replace this xml file with rooms in a DB
            Console.Write("Attempting to read Rooms.xml...");
            this.ReadRoomFile();
            if (rooms.Count > 0)
            {
                Console.WriteLine(" Success!\r\nRead {0} rooms from the file.", rooms.Count);
            }

            //TODO: add code for loading npcs from DB
            NPC npc = new NPC(0, 0, 0, "An NPC", "An NPC is standing here.  It has no form and nothing on.", new List<string> { "NPC" }, 60000, 10, 1, this.players, this.rooms, 10, 1, 1, 1, 1, 1);
            this.npcs.Add( npc);

            //creating some test items
            //TODO: add code for loading respawnable items from DB
            itemList.Add(new Dagger("A dagger", "A very generic, basic dagger.", 1, 0, 0, 0, 10000, true, new List<string> { "dagger", "dag" }, 10, 10));
            itemList.Add(new Pants("A pair of cotton pants", "A pair of white, cotton pants.", 1, 0, 0, 0, 60000, true, new List<string> { "cotton", "pants" }, 0));
            itemList.Add(new Shirt("A cotton shirt", "A long-sleeved, white, cotton shirt.", 1, 0, 0, 0, 60000, true, new List<string> { "cotton", "shirt" }, 0));
            itemList.Add(new Headwear("A cotton hood", "A white, cotton hood.", 1, 0, 0, 0, 60000, true, new List<string> { "cotton", "hood" }, 0));
            itemList.Add(new Gloves("A pair of cotton gloves", "A pair of soft, white, cotton gloves.", 1, 0, 0, 0, 60000, true, new List<string> { "cotton", "gloves" }, 0));
            itemList.Add(new Boots("A pair of soft, leather boots", "A pair of soft, supple, leather boots with a thin leather sole.", 1, 0, 0, 0, 60000, true, new List<string> { "boots" }, 1));

            itemList.Add(new Light("A torch", "A simple torch made from a branch and an oily rag.", .5, 0, 0, 0, 10000, true, new List<string> { "torch" }, 90000));

            //test skill data
            //TODO: add code for reading skills from a file or DB so that MUD authors can 'dynamically' create diverse skill trees with minimal/no coding
            List<Skill> skillTreeSkills = new List<Skill>();
            skillTreeSkills.Add(new Skill("Dodge", 1, null));
            skillTreeSkills.Add(new Skill("Parry", 1, null));
            skillTreeSkills.Add(new Skill("Hide", 2, null));
            skillTreeSkills.Add(new Skill("Sneak", 3, null, 5, new Dictionary<string, int>() {{"hide", 50}}));
            skillTreeSkills.Add(new Skill("Ambush", 4, null, 7, new Dictionary<string, int> { { "sneak", 50 }, { "hide", 75 } }));

            Console.WriteLine("Creating skill tree...");
            this.skillTree = new SkillTree(skillTreeSkills);

            Console.WriteLine("Initializing skills...");
            this.skillTree.InitializeSkillTree();
        }
Ejemplo n.º 3
0
        private void DisplaySkillTree()
        {
            StringBuilder sb = new StringBuilder();
            SkillTree tempSkillTree = new SkillTree();

            sb.AppendLine("\r\nSkill Tree\r\nFor more information type \"help <skillname>\"");
            sb.AppendLine("Name\tLevel Req");

            Monitor.TryEnter(skilltreelock, 3000);
            try
            {
                tempSkillTree = this.universalSkillTree;
            }
            catch (Exception ex)
            {
                Debug.Print(ex.Message);
                Debug.Print(ex.StackTrace);
            }
            finally
            {
                Monitor.Exit(skilltreelock);
            }

            foreach (Skill s in tempSkillTree.Skills)
            {
                sb.AppendLine(s.SkillName + "\tLvl " + s.LevelRequired);
            }

            this.writeToClient(sb.ToString());
        }
Ejemplo n.º 4
0
        public void InitializeSkill(SkillTree skillTree)
        {
            if (this.preliminaryPrerequisites.Count > 0)
            {
                foreach(KeyValuePair<string, int> preReq in this.preliminaryPrerequisites)
                {
                    if (preReq.Value <= 0 || preReq.Value > 100)
                    {
                        //TODO: throw an exception.  Can't have a prerequisite that is less than 0% proficiency or greater than 100%
                    }
                    else
                    {
                        Skill querySkill = (from skill in skillTree.Skills
                                            where skill.SkillName.ToLower() == preReq.Key.ToLower()
                                            select skill).FirstOrDefault();

                        if (querySkill != null)
                        {
                            this.finalPrerequisites.Add(querySkill, preReq.Value);
                        }
                        else
                        {
                            //TODO: throw an exception.  Couldn't find the skill defined in the skill tree.  User should go back and review their skill tree file to ensure that all "prerequisite" skills that are referenced are defined.
                            throw new Exception();
                        }
                    }
                }
            }
        }