コード例 #1
0
        protected override void Handle(UserPlayerDelete data, PlayerConnection connection)
        {
            var player = gameData.GetPlayer(data.PlayerId);

            if (player == null)
            {
                return;
            }

            worldProcessor.RemovePlayer(player);

            gameData.Remove(gameData.GetAppearance(player.AppearanceId));
            gameData.Remove(gameData.GetTransform(player.TransformId));
            gameData.Remove(gameData.GetAttributes(player.AttributesId));
            gameData.Remove(gameData.GetProfessions(player.ProfessionsId));

            var items = gameData.GetAllPlayerItems(player.Id);

            foreach (var item in items)
            {
                gameData.Remove(item);
            }

            gameData.Remove(player);

            SendPlayerList(connection);
        }
コード例 #2
0
        private void SetValue <T>(int entityId, string skill, T value)
        {
            var attributesId = isPlayer ? gameData.GetPlayer(entityId).AttributesId : gameData.GetNpc(entityId).AttributesId;
            var attributes   = gameData.GetAttributes(attributesId);

            var attr = GetAttributeProperty(skill);

            if (attr != null)
            {
                attr.SetValue(attributes, value);
                return;
            }

            if (isPlayer)
            {
                var professions = gameData.GetProfessions(gameData.GetPlayer(entityId).ProfessionsId);
                var prof        = GetProfessionProperty(skill);
                if (prof != null)
                {
                    prof.SetValue(professions, value);
                }
            }
        }
コード例 #3
0
ファイル: NpcAdd.cs プロジェクト: zerratar/Ravenfall-Server
        public static NpcAdd Create(IGameData gameData, NpcInstance obj, Transform transform)
        {
            var npc   = gameData.GetNpc(obj.NpcId);
            var npcid = npc.NpcId;

            return(new NpcAdd
            {
                ServerId = obj.Id,
                NpcId = npcid,
                Level = npc.Level,
                Health = obj.Health,
                Endurance = obj.Endurance,
                Attributes = gameData.GetAttributes(npcid),
                Position = transform.GetPosition(),
                Rotation = transform.GetRotation(),
                Destination = transform.GetDestination()
            });
        }
コード例 #4
0
        public static PlayerAdd Create(IGameData gameData, Player player)
        {
            var appearance = gameData.GetAppearance(player.AppearanceId);
            var transform  = gameData.GetTransform(player.TransformId);
            var attributes = gameData.GetAttributes(player.AttributesId);

            return(new PlayerAdd
            {
                PlayerId = player.Id,
                Name = player.Name,
                Endurance = player.Endurance,
                Attributes = attributes,
                Position = transform.GetPosition(),
                Destination = transform.GetDestination(),
                Appearance = appearance,
                Health = player.Health,
                Level = player.Level
            });
        }
コード例 #5
0
        public static MyPlayerAdd Create(
            IGameData gameData,
            Player player,
            IReadOnlyList <InventoryItem> items)
        {
            var appearance  = gameData.GetAppearance(player.AppearanceId);
            var transform   = gameData.GetTransform(player.TransformId);
            var attributes  = gameData.GetAttributes(player.AttributesId);
            var professions = gameData.GetProfessions(player.ProfessionsId);

            var itemIds = new int[items.Count];
            var amounts = new long[items.Count];

            for (var i = 0; i < items.Count; ++i)
            {
                itemIds[i] = items[i].ItemId;
                amounts[i] = items[i].Amount;
            }

            return(new MyPlayerAdd
            {
                PlayerId = player.Id,
                Name = player.Name,
                Experience = player.Experience,
                Level = player.Level,
                Health = player.Health,
                Endurance = player.Endurance,
                Position = transform.GetPosition(),
                Attributes = attributes,
                Professions = professions,
                Appearance = appearance,
                InventoryItemId = itemIds,
                InventoryItemAmount = amounts,
                Coins = player.Coins
            });
        }
コード例 #6
0
    private bool OnPlayerAfflictDamage(
        Player player,
        NpcInstance npc,
        TimeSpan totalTime,
        TimeSpan deltaTime)
    {
        var attackType = playerState.GetAttackType(player);

        if (!playerState.InCombat(player, npc))
        {
            ExitCombat(player, npc, attackType);
            return(false);
        }

        var npcRecord        = gameData.GetNpc(npc.NpcId);
        var npcAttributes    = gameData.GetAttributes(npcRecord.AttributesId);
        var playerAttributes = gameData.GetAttributes(player.AttributesId);

        var session = sessionManager.Get(player);
        var damage  = CalculateDamage(playerAttributes, npcAttributes);

        var trainingSkill = SkillAttack;

        npc.Health -= damage;

        worldProcessor.DamageNpc(player, npc, damage, npc.Health, npcAttributes.Health);

        if (npc.Health <= 0)
        {
            session.Npcs.States.ExitCombat(npc);

            // he ded
            worldProcessor.KillNpc(player, npc);

            // note(zerratar): action that kills the enemy shouldn't be the one responsible for respawning
            //                 this should be moved to a INpcProcessor or similar called from the WorldProcessor Update
            worldProcessor.SetEntityTimeout(gameData.GetNpc(npc.NpcId).RespawnTimeMs, player, npc, OnRespawn);

            var experience   = GameMath.CombatExperience(npcRecord.Level);
            int levelsGaiend = playerStatsProvider.AddExperience(player.Id, trainingSkill, experience);
            var newExp       = playerStatsProvider.GetExperience(player.Id, trainingSkill);
            var newLevel     = playerStatsProvider.GetLevel(player.Id, trainingSkill);

            //var itemDrops = npcProvider.GetItemDrops(npc);
            //foreach (var itemDrop in itemDrops)
            //{
            //    if (random.NextDouble() > itemDrop.DropChance)
            //        continue;
            //    worldProcessor.AddPlayerItem(player, gameData.GetItem(itemDrop.ItemId));
            //}

            worldProcessor.UpdatePlayerStat(player, trainingSkill, newLevel, newExp);

            if (levelsGaiend > 0)
            {
                worldProcessor.PlayerStatLevelUp(player, trainingSkill, levelsGaiend);
            }

            ExitCombat(player, npc, attackType);
            return(true);
        }

        PlayerAttack(player, npc, attackType);
        return(false);
    }