Example #1
0
        /// <summary>
        /// Given an NPC and player, begins a dialog between the two.
        /// </summary>
        /// <param name="player"></param>
        /// <param name="npc"></param>
        public void BeginDialog(Player player, Npc npc)
        {
            var npcDialog = npc.DialogTemplate;

            DialogProvider dialogProvider;

            if (_dialogProviders[player].FindProviderFor(npc) == null)
            {

                //TODO: Frequent IO hit; bad
                dialogProvider = new DialogProvider(npcDialog);

                // Insert the provider
                _dialogProviders[player].InsertProviderFor(npc, dialogProvider);

                dialogProvider.DialogNodeChanged -= DialogProviderOnDialogNodeChanged;
                dialogProvider.DialogNodeChanged += DialogProviderOnDialogNodeChanged;

            }
            else
            {
                dialogProvider = _dialogProviders[player].FindProviderFor(npc);
            }

            // Begin the dialog
            dialogProvider.BeginDialogWith(player);
        }
Example #2
0
        public DialogNode FollowLinkWithAndUpdate(Player player, int linkId)
        {
            var node = _playerDialogNodeStateTable[player];

            if (linkId > node.Links.Count)
                throw new ArgumentOutOfRangeException("linkId", "linkId must be within the range of the current node's link count.");

            var link = node.Links[linkId];

            // We should do nothing if the user decided to use a link that was invalid
            if (!link.IsAvailable(player))
            {
                Logger.Instance.Warn("{0} attempted to follow a link with ID {1} which they were not allowed to use.", player, linkId);
                return null;
            }

            // Perform actions as required
            PerformLinkActions(player, link);

            // Get and return the next available node for the given link
            _playerDialogNodeStateTable[player] = link.NextNode;

            OnDialogNodeChanged(player, link.NextNode);

            return link.NextNode;
        }
        public static void MoveToHandler(Player player, List<string> arguments)
        {
            var x = int.Parse(arguments[0]);
            var y = int.Parse(arguments[1]);

            player.Teleport(new Vector2(x, y));
        }
        public bool HasRequirements(Player player, int progress)
        {
            var quest = player.QuestLog.FirstOrDefault(x => x.Quest.QuestId == QuestId);

            if (quest != null)
                return quest.State == QuestState.Finished;

            return false;
        }
        public static Player CreateHero(UserHero userHero, GameClient gameClient)
        {
            var entity = new Player("male_base", gameClient, userHero);
            entity.Position = new Vector2(userHero.PositionX, userHero.PositionY);
            entity.Name = userHero.Name;

            // Copy the stats from the DB into the player
            CopyStatsFromTemplateToCharacter(userHero, entity);

            return entity;
        }
Example #6
0
        /// <summary>
        /// Begins a transaction with a player, resetting state if it contained any.
        /// </summary>
        /// <param name="player"></param>
        /// <returns></returns>
        public DialogNode BeginDialogWith(Player player)
        {
            if (!_playerDialogNodeStateTable.ContainsKey(player))
                _playerDialogNodeStateTable.Add(player, _rootDialogNode);
            else
                ResetState(player);

            OnDialogNodeChanged(player, _rootDialogNode);

            return _playerDialogNodeStateTable[player];
        }
Example #7
0
        public bool IsRequirementsMet(Player player, List<int> progress)
        {
            bool requirementsMet = true;

            for (int index = 0; index < Requirements.Count; index++)
            {
                var requirement = Requirements[index];
                requirementsMet &= requirement.HasRequirements(player, progress[index]);
            }

            return requirementsMet;
        }
        //NOTICE: PLEASE CLEANUP ANYTHING YOU REGISTER HERE, OTHERWISE THINGS WILL GET CHAOTIC
        private void MonitorPlayer(Player player)
        {
            player.EquipmentChanged += PlayerOnEquipmentChanged;
            player.CharacterStats.CurrentValueChanged += CharacterStatsOnCurrentValueChanged;
            player.LearnedSkill += PlayerOnLearnedSkill;
            player.BackpackChanged += PlayerOnBackpackChanged;

            player.AcceptedQuest += PlayerOnAcceptedQuest;

            player.ExperienceChanged += PlayerOnExperienceChanged;
            player.LevelChanged += PlayerOnLevelChanged;
        }
Example #9
0
        /// <summary>
        /// Consumes a specific message
        /// </summary>
        /// <param name="player"></param>
        /// <param name="message"></param>
        public bool ParseAndHandleMessage(Player player, string message)
        {
            if (message.Length > 2)
            {
                var command = message.Split(" ".ToCharArray())[0].ToLower().Substring(1);
                var arguments = GetArgumentList(message);

                // Fire off the handler now
                if (_packetHandlers.ContainsKey(command))
                {
                    _packetHandlers[command](player, arguments);
                    return true;
                }
            }

            return false;
        }
        public static void WarpToHandler(Player player, List<string> arguments)
        {
            // Get the map ID an argument, the other parameters are optional
            var zoneId = int.Parse(arguments[0]);

            int x = player.X;
            int y = player.Y;

            // If we had exactly 3 parameters (must have had a X, Y as well)
            if (arguments.Count == 3)
            {
                x = int.Parse(arguments[1]);
                y = int.Parse(arguments[2]);
            }

            // Move the player to the zone they have requested
            ZoneManager.Instance.SwitchToZoneAndPosition(player, zoneId, new Vector2(x, y));
        }
Example #11
0
        public bool CanPlayerGetQuest(Quest quest, Player player)
        {
            // If the player has the quest completed already, decline
            foreach (var entry in player.QuestLog)
            {
                if (entry.Quest.QuestId == quest.QuestId && entry.State != QuestState.Available)
                    return false;
            }

            // Check if the player
            foreach (var requirement in quest.StartRequirements)
            {
                if (!requirement.HasRequirements(player, 0))
                    return false;
            }

            // The player can flag this quest up
            return true;
        }
 public static void LogoutCommandHandler(Player player, List<string> arguments)
 {
     player.Client.Connection.Disconnect("The player logged out forcefully.");
 }
Example #13
0
 private static void EquipFromSlotIdInInventory(ClientHeroUseItemPacket packet, Player hero)
 {
     // Attempt to equip the item
     var success = hero.TryEquipItem(packet.SlotId);
 }
Example #14
0
 public void EndSession()
 {
     _player = null;
 }
 public static void FullHeal(Player player, List<string> arguments)
 {
     player.CharacterStats[StatTypes.Hitpoints].CurrentValue =
         player.CharacterStats[StatTypes.Hitpoints].MaximumValue;
 }
        private void PlayerOnEquipmentChanged(Equipment equipment, Player player, EquipmentSlot slot)
        {
            var request = new ServerEquipmentUpdatePacket(equipment, slot);
            player.Client.Send(request);

            // Send notification to the client
            var request2 = new ServerSendGameMessagePacket(GameMessage.EquipmentChanged);
            player.Client.Send(request2);
        }
Example #17
0
 public void BeginSession(Player player)
 {
     _player = player;
 }
Example #18
0
        // Use this for sending notifications to client
        private void DialogProviderOnDialogNodeChanged(Player player, DialogNode newNode)
        {
            Logger.Instance.Info("{0} is advancing dialog.", player);

            string message = "The conversation ends.";
            ICollection<ExpandoObject> links = new Collection<ExpandoObject>();

            if (newNode != null)
            {
                message = newNode.Text;

                for (int i = 0; i < newNode.Links.Count; i++)
                {
                    var link = newNode.Links[i];

                    if (link.IsAvailable(player))
                    {
                        dynamic entry = new ExpandoObject();
                        entry.link = link.Text;
                        entry.index = i;

                        links.Add(entry);

                    }

                }

            }

            var packet = new ServerDialogPresentPacket(message, links);
            player.Client.Send(packet);
        }
 public NpcEventReceiverContext(Player localPlayer, Npc localNpc)
 {
     LocalPlayer = localPlayer;
     LocalNpc = localNpc;
 }
Example #20
0
 public void AdvanceDialog(Player player, Npc npc, int linkId)
 {
     // Advance the dialog, which will fire an update to the client anyway
     var dialogProvider = _dialogProviders[player].FindProviderFor(npc);
     dialogProvider.FollowLinkWithAndUpdate(player, linkId);
 }
        private void PlayerOnExperienceChanged(int newValue, int oldValue, Player player)
        {
            if (newValue > oldValue)
            {

                var packet = new ServerSendGameMessagePacket(GameMessage.GainExperience, new List<string>()
                {
                    (newValue - oldValue).ToString()
                });

                player.Client.Send(packet);
            }
        }
        /// <summary>
        /// This is called to synchronize this new fact to the player
        /// </summary>
        /// <param name="skill">The skill that was learned and to be synced</param>
        /// <param name="player">The player that has learned this skill</param>
        private void PlayerOnLearnedSkill(Skill skill, Player player)
        {
            // Notify the player that they learned this skill, send it over
            var packet = new ServerSkillChangePacket(player.Skills);
            player.Client.Send(packet);

            Logger.Instance.Info("{0} has learned the skill {1}.", player.Name, skill.SkillTemplate.Name);
        }
 private void PlayerOnLevelChanged(int newValue, int oldValue, Player player)
 {
     // Send a notification to everyone in the zone
     player.Zone.ChatChannel.SendMessage(GameMessage.LevelUp, new List<string>()
     {
         (player.Name).ToString(),
         player.Level.ToString()
     });
 }
 public static void Rename(Player player, List<String> arguments)
 {
     var name = String.Join(" ", arguments);
     player.Name = name;
 }
        private void NeglectPlayer(Player player)
        {
            player.EquipmentChanged -= PlayerOnEquipmentChanged;
            player.CharacterStats.CurrentValueChanged -= CharacterStatsOnCurrentValueChanged;
            player.LearnedSkill -= PlayerOnLearnedSkill;
            player.BackpackChanged -= PlayerOnBackpackChanged;

            //TODO: Re-enable me
            player.AcceptedQuest -= PlayerOnAcceptedQuest;

            player.ExperienceChanged -= PlayerOnExperienceChanged;
            player.LevelChanged -= PlayerOnLevelChanged;
        }
 private void ActiveStatusEffectsOnEffectAdded(Player player, StatusEffect effect)
 {
     throw new NotImplementedException();
 }
 public static void ServerTimeHandler(Player player, List<string> arguments)
 {
     // Replies with the current server time
     var time = DateTime.Now;
     player.Client.Send(new ServerSendGameMessagePacket(GameMessage.CurrentTime, new List<string>() { time.ToLongTimeString()}));
 }
Example #28
0
 private void OnPlayerAdded(Player player)
 {
     _dialogProviders.Add(player, new NpcDialogCollection());
 }
Example #29
0
        private static void PersistPlayer(Player player)
        {
            using (var context = new GameDatabaseContext())
            {
                var hero = context.Characters.First(x => x.UserHeroId == player.UserId);

                // Load quest info
                context.Entry(hero).Collection(x => x.QuestInfo).Load();

                foreach (var x in hero.QuestInfo)
                {
                    context.Entry(x).Collection(a => a.RequirementProgress).Load();

                    var l = x.RequirementProgress.ToList();
                    foreach (var n in l)
                        context.Entry(n).State = EntityState.Deleted;

                }

                context.Entry(hero).Collection(x => x.Inventory).Load();
                context.Entry(hero).Collection(x => x.Equipment).Load();
                context.Entry(hero).Collection(x => x.Flags).Load();

                hero.Name = player.Name;
                hero.PositionX = (int)player.Position.X;
                hero.PositionY = (int)player.Position.Y;
                hero.ZoneId = player.Zone.Id;

                // Persist stats
                hero.Hitpoints = (int)player.CharacterStats[(int)StatTypes.Hitpoints].CurrentValue;
                hero.Strength = (int)player.CharacterStats[(int)StatTypes.Strength].CurrentValue;
                hero.Intelligence = (int)player.CharacterStats[(int)StatTypes.Intelligence].CurrentValue;
                hero.Dexterity = (int)player.CharacterStats[(int)StatTypes.Dexterity].CurrentValue;
                hero.Luck = (int)player.CharacterStats[(int)StatTypes.Luck].CurrentValue;
                hero.Vitality = (int)player.CharacterStats[(int)StatTypes.Vitality].CurrentValue;
                hero.MaximumHitpoints = (int)player.CharacterStats[(int)StatTypes.Hitpoints].MaximumValue;
                hero.Mind = (int)player.CharacterStats[StatTypes.Mind].CurrentValue;

                hero.SkillResource = (int)player.CharacterStats[StatTypes.SkillResource].CurrentValue;
                hero.MaximumSkillResource = (int)player.CharacterStats[StatTypes.SkillResource].MaximumValue;

                hero.Experience = player.Experience;
                hero.Level = player.Level;

                hero.Flags = player.Flags;

                //TODO: Need better tracking code here, incrementing the row needlessly here

                // For now though, we don't care...
                hero.QuestInfo.ToList().ForEach(r => context.UserQuestInfo.Remove(r));

                context.SaveChanges();
                //context.SaveChanges();

                foreach (var entry in player.QuestLog)
                {

                    var temp = new List<UserQuestRequirements>();

                    for (int index = 0; index < entry.Progress.Count; index++)
                    {
                        var x = entry.Progress[index];

                        var questRequirementProgress = new UserQuestRequirements()
                        {
                            Progress = x
                        };

                        if (entry.QuestInfo.RequirementProgress.Count - 1 >= index)
                            questRequirementProgress.UserQuestRequirementId =
                                entry.QuestInfo.RequirementProgress[index].QuestInfo.UserQuestInfoId;

                        temp.Add(questRequirementProgress);
                    }

                    var quest = new UserQuestInfo()
                   {
                       QuestId = entry.QuestInfo.QuestId,
                       State = entry.State,
                       UserQuestInfoId = entry.QuestInfo.UserQuestInfoId,
                       UserHero = hero,
                       RequirementProgress = temp,
                       QuestProgress = entry.QuestInfo.QuestProgress
                   };

                    hero.QuestInfo.Add(quest);

                }

                hero.Inventory.ToList().ForEach(r => context.UserItems.Remove(r));

                foreach (var inventorySlot in player.Backpack.Storage)
                {
                    var x = new UserItem(inventorySlot.Value.Item.Id, inventorySlot.Value.Amount, inventorySlot.Key);
                    hero.Inventory.Add(x);
                }

                hero.Equipment.ToList().ForEach(r => context.UserEquipments.Remove(r));

                foreach (var equipmentPiece in player.Equipment)
                {
                    if (equipmentPiece == null)
                        continue;

                    var x = new UserEquipment()
                    {
                        ItemId = equipmentPiece.Id,
                        Slot = equipmentPiece.Slot,
                        UserEquipmentId = 0
                    };

                    hero.Equipment.Add(x);
                }

                context.Entry(hero).State = EntityState.Modified;

                // Flush
                context.SaveChanges();

            }
        }
Example #30
0
        private void OnPlayerRemoved(Player player)
        {
            // Remove the key if it exists
            if (_dialogProviders.ContainsKey(player))
            {
                foreach (var provider in _dialogProviders[player])
                    provider.RemoveState(player);
            }

            _dialogProviders.Remove(player);
        }