protected bool HandleObjectTick(Player player, GameObjectInstance obj, TimeSpan totalTime, TimeSpan deltaTime) { var session = Sessions.Get(player); if (!session.Objects.HasAcquiredLock(obj, player)) { StopAnimation(player, obj); return(true); } var skillLevel = statsProvider.GetLevel(player.Id, skillName); var chance = 0.05f + skillLevel * 0.05f; if (random.NextDouble() <= chance) { StartAnimation(player, obj); return(false); } var gobj = GameData.GetGameObject(obj.ObjectId); var levelsGaiend = statsProvider.AddExperience(player.Id, skillName, gobj.Experience); var itemDrops = session.Objects.GetItemDrops(obj); foreach (var itemDrop in itemDrops) { if (random.NextDouble() > itemDrop.DropChance) { continue; } World.AddPlayerItem(player, GameData.GetItem(itemDrop.ItemId)); } var exp = statsProvider.GetExperience(player.Id, skillName); World.UpdatePlayerStat(player, skillName, skillLevel + levelsGaiend, exp); if (levelsGaiend > 0) { World.PlayerStatLevelUp(player, skillName, levelsGaiend); } StopAnimation(player, obj); if (AfterAction != null) { AfterAction?.Invoke(this, new AfterActionEventArgs(player, obj)); } return(true); }
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); }