public void UnstuckPlayer(Player player) { Npc nearNpc = null; double distance = double.MaxValue; player.Instance.Npcs.Each(npc => { double dist = npc.Position.FastDistanceTo(player.Position); if (dist < distance) { distance = dist; nearNpc = npc; } }); var pos = TeleportService.IslandOfDawnSpawn; if (nearNpc != null) { pos = Geom.GetNormal((short)RandomUtilities.Random().Next(0, short.MaxValue)) .Multiple(150) .Add(nearNpc.Position) .SetZ(nearNpc.Position.Z + 200) .ToWorldPosition(); pos.MapId = player.Position.MapId; } Global.TeleportService.ForceTeleport(player, pos); }
public virtual void Init(Creature creature) { Creature = creature; Npc = creature as Npc; Player = creature as Player; Random = new Random((int)(DateTime.Now.Ticks + RandomUtilities.Random().Next(int.MinValue, (int)Math.Abs(creature.Position.X)))); }
private void CreateGroup(IConnection connection) { var npcs = Global.VisibleService.FindTargets(connection.Player, connection.Player.Position, 50, TargetingAreaType.Enemy); npcs.Sort((c1, c2) => { Npc npc1 = c1 as Npc; Npc npc2 = c2 as Npc; if (npc1 == null || npc2 == null) { return(0); } return(npc2.NpcTemplate.Size.GetHashCode() .CompareTo(npc1.NpcTemplate.Size.GetHashCode())); }); int counter = 0; int startAngle = RandomUtilities.Random().Next(0, 359); foreach (var creature in npcs) { Npc npc = creature as Npc; if (npc == null) { continue; } int count = int.Parse(GetValue(connection, "Enter count of: [" + npc.NpcTemplate.Name + "]")); if (count > 0) { for (int i = 0; i < count; i++) { SpawnTemplate spawnTemplate = npc.SpawnTemplate.Clone(); spawnTemplate.X += (float)(150f * Math.Cos(startAngle + counter * 30) * counter / 2 / Math.PI + RandomUtilities.Random().Next(-25, 25)); spawnTemplate.Y += (float)(150f * Math.Sin(startAngle + counter * 30) * counter / 2 / Math.PI + RandomUtilities.Random().Next(-25, 25)); Global.MapService.SpawnTeraObject(MapService.CreateNpc(spawnTemplate), npc.Instance); counter++; } Global.MapService.DespawnTeraObject(npc); } } }
private static void TrySetCrit(Creature attacker, AttackResult result) { int chance = (attacker is Player) ? 10 : 30; chance += attacker.GameStats.CritChanse - result.Target.GameStats.CritResist; if (chance < 0) { chance = 2; } if (RandomUtilities.Random().Next(0, 100) > chance) { return; } result.Damage *= attacker.GameStats.CritPower; result.AttackType = AttackType.Critical; }
private static void ApplyPassivity(Player player, Condition condition, Passivity passivity, AttackResult result) { if (!CheckCondition(condition, passivity)) { return; } if (passivity.Probability >= 0.001f && 1.0f - passivity.Probability > 0.001f) { if (RandomUtilities.Random().Next(0, 100) > passivity.Probability * 100) { return; } } switch (passivity.Type) { // Damage block case 109: if (result.AttackType != AttackType.Normal || !result.Target.EffectsImpact.IsBlockFrontAttacks) { return; } if (result.AngleDif < 135 || passivity.Value < result.Damage) { return; } result.Damage = 0; result.AttackType = AttackType.Block; break; // Heal modifier case 168: case 169: switch (passivity.Method) { case 2: result.HpDiff += (int)passivity.Value; break; case 3: result.HpDiff = (int)passivity.Value * result.HpDiff; break; } break; // Do more damage when attack ... case 152: if (passivity.MobSize != NpcSize.All) { if (result.Target is Player && passivity.MobSize != NpcSize.Player) { return; } if (result.Target is Npc && ((Npc)result.Target).NpcTemplate.Size != passivity.MobSize) { return; } } switch (passivity.Method) { case 2: result.Damage += (int)passivity.Value; break; case 3: result.Damage = (int)(passivity.Value * result.Damage); break; } break; // Chance to regenerate MP when combat starts. case 207: Communication.Global.FeedbackService.MpChanged(player, (int)passivity.Value, player); break; } }
public void CreateDrop(Npc npc, Player player) { if (RandomUtilities.IsLuck(75)) { var money = (int)(10 * Data.Data.NpcExperience[npc.GetLevel()] / RandomUtilities.Random().Next(20, 60)); player.Instance.AddDrop( new Item { Owner = player, Npc = npc, ItemId = 20000000, Count = money, Position = Geom.RandomCirclePosition(npc.Position, RandomUtilities.Random().Next(60, 100)), Instance = player.Instance, }); } if (!Data.Data.Drop.ContainsKey(npc.NpcTemplate.FullId)) { return; } List <int> items = Data.Data.Drop[npc.NpcTemplate.FullId]; if (items == null) { return; } int count = 0; int rate = RandomUtilities.Random().Next(0, 2500); if (rate < 10) { count = 6; } else if (rate < 30) { count = 5; } else if (rate < 90) { count = 4; } else if (rate < 270) { count = 3; } else if (rate < 600) { count = 2; } else if (rate < 1800) { count = 1; } if (items.Count < count) { count = items.Count; } for (int i = 0; i < count; i++) { int itemId = items[RandomUtilities.Random().Next(0, items.Count)]; if (!Data.Data.ItemTemplates.ContainsKey(itemId)) { continue; } player.Instance.AddDrop( new Item { Owner = player, Npc = npc, ItemId = itemId, Count = 1, Position = Geom.RandomCirclePosition(npc.Position, RandomUtilities.Random().Next(60, 100)), Instance = player.Instance, }); } }
public void Action() { if (SkillsCount == 0) { return; } if (Npc.Attack != null && !Npc.Attack.IsFinished) { return; } lock (Lock) { Creature target = null; int maxHate = int.MinValue; foreach (var hate in Hate) { if (hate.Key.Position.DistanceTo(Npc.Position) > 1500 || hate.Key.LifeStats.IsDead()) { Damage.Remove(hate.Key); Hate.Remove(hate.Key); return; } if (hate.Value > maxHate) { target = hate.Key; maxHate = hate.Value; } } Npc.Target = target; } if (Npc.Target == null) { return; } if (SelectedSkill == null) { if (RandomUtilities.Random().Next(0, 1000) < 250) { Global.SkillEngine.UseSkill(Npc, MoveSkills[RandomUtilities.Random().Next(0, MoveSkills.Count)]); return; } SelectedSkill = AttackSkills[RandomUtilities.Random().Next(0, AttackSkills.Count)]; } int distance = SeUtils.GetAttackDistance(SelectedSkill); if (Npc.Position.DistanceTo(Npc.Target.Position.X, Npc.Target.Position.Y) > distance + 30) { long now = RandomUtilities.GetCurrentMilliseconds(); if (now > LastMoveUts + 1000) { LastMoveUts = now; ((NpcAi)Npc.Ai).MoveController.MoveTo(Npc.Target.Position, distance); } return; } ((NpcAi)Npc.Ai).MoveController.Stop(); Global.SkillEngine.UseSkill(Npc, SelectedSkill); SelectedSkill = null; }
public static WorldPosition RandomCirclePosition(WorldPosition position, int distance) { short heading = (short)RandomUtilities.Random().Next(short.MinValue, short.MaxValue); return(GetNormal(heading).Multiple(distance).Add(position).ToWorldPosition()); }