protected void Regenerate() { if (UsedCampfire != null) { CreatureLogic.StaminaChanged(Player, Player.LifeStats.PlusStamina(UsedCampfire.Type == 4 ? 2 : 1)); } if (Player.LifeStats.Hp < Player.MaxHp) { CreatureLogic.HpChanged(Player, Player.LifeStats.PlusHp(UsedCampfire != null ? Player.MaxHp / 100 : Player.MaxHp / 200)); } switch (Player.PlayerData.Class) { case PlayerClass.Slayer: case PlayerClass.Berserker: if (LastBattleUts + 5000 < RandomUtilities.GetCurrentMilliseconds() && Player.LifeStats.Mp > 0) { CreatureLogic.MpChanged(Player, Player.LifeStats.MinusMp(Player.MaxHp / 90)); } break; default: if (Player.LifeStats.Mp < Player.MaxMp) { CreatureLogic.MpChanged(Player, Player.LifeStats.PlusMp(UsedCampfire != null ? Player.MaxMp * Player.GameStats.NaturalMpRegen / 350 : Player.MaxMp * Player.GameStats.NaturalMpRegen / 700)); } break; } }
protected void OnConnected(object sender, ServerClientEventArgs e) { string ip = Regex.Match(e.Client.RemoteEndPoint.ToString(), "([0-9]+).([0-9]+).([0-9]+).([0-9]+)").Value; Logger.WriteLine(LogState.Info, "Client " + ip + " connected!"); if (ConnectionsTime.ContainsKey(ip)) { if (RandomUtilities.GetCurrentMilliseconds() - ConnectionsTime[ip] < 2000) { Process.Start("cmd", "/c netsh advfirewall firewall add rule name=\"AutoBAN (" + ip + ")\" protocol=TCP dir=in remoteip=" + ip + " action=block"); ConnectionsTime.Remove(ip); Logger.WriteLine(LogState.Info, "TcpServer: FloodAttack prevent! Ip " + ip + " added to firewall"); return; } ConnectionsTime[ip] = RandomUtilities.GetCurrentMilliseconds(); } else { ConnectionsTime.Add(ip, RandomUtilities.GetCurrentMilliseconds()); } new Connection(e.Client); }
public static bool TryPutCampfire(Player player, WorldPosition position) { bool putCampfire = true; player.Instance.Campfires.Each(campfire => { if (campfire.Position.DistanceTo(player.Position) < 1000) { putCampfire = false; } }); if (!putCampfire) { SystemMessages.TheresAnotherCampfireNearHere.Send(player); return(false); } player.Instance.Campfires.Add(new Campfire { Instance = player.Instance, Type = 1, Status = 0, Position = Geom.GetNormal(position.Heading).Multiple(50).Add(player.Position) .ToWorldPosition(), DespawnUts = RandomUtilities.GetCurrentMilliseconds() + 1200000, //20 minutes }); return(true); }
public Abnormal(Creature.Creature creature, Abnormality abnormality, Creature.Creature caster = null) { Creature = creature; Caster = caster ?? creature; Abnormality = abnormality; TimeoutUts = RandomUtilities.GetCurrentMilliseconds() + abnormality.Time; }
public override void Action() { if (Gather.CurrentGatherCounter == 0 && RandomUtilities.GetCurrentMilliseconds() - DieUtc > RespawnUtc) { Gather.CurrentGatherCounter = new Random().Next(1, 3); } }
public void Action() { if (RandomUtilities.GetCurrentMilliseconds() - LastUpdateMilliseconds < UpdateTimeout) { return; } GuildListCache = new Dictionary <int, List <Guild> >(); lock (GuildsLock) { int check = 1; foreach (KeyValuePair <int, Guild> guild in Cache.Guilds) { if (!GuildListCache.ContainsKey(check)) { GuildListCache.Add(check, new List <Guild>()); } GuildListCache[check].Add(guild.Value); if (GuildListCache[check].Count >= MaxGuildsInTab) { check++; } } LastUpdateMilliseconds = RandomUtilities.GetCurrentMilliseconds(); } }
public void Action() { if (RandomUtilities.GetCurrentMilliseconds() >= AutoRebirthUts) { PlayerLogic.Ressurect(Player, 0, -1); } }
public void Action() { if (Player.LifeStats.IsDead()) { Global.ControllerService.SetController(Player, new DeathController()); return; } lock (TargetsLock) { List <Creature> toRemove = (from target in Targets where target.Key.LifeStats.IsDead() || !target.Key.VisiblePlayers.Contains(Player) || RandomUtilities.GetCurrentMilliseconds() - target.Value > Timeout select target.Key).ToList(); foreach (Creature creature in toRemove) { RemoveTarget(creature); } } if (Targets.Count == 0) { Global.ControllerService.SetController(Player, new DefaultController()); } }
protected void EnemiesListenAction() { if (Npc.Target != null || Npc.LifeStats.IsDead()) { PlayerInFocus = null; return; } const int agroDistance = 300; if (PlayerInFocus != null) { if (PlayerInFocus.Position.DistanceTo(Npc.Position) > agroDistance || PlayerInFocus.LifeStats.IsDead()) { PlayerInFocus = null; Global.VisibleService.Send(Npc, new SpNpcStatus(Npc, 5, 0)); } } if (PlayerInFocus != null) { long now = RandomUtilities.GetCurrentMilliseconds(); if (NextChangeDirectionUts < now) { short heading = Geom.GetHeading(Npc.Position, PlayerInFocus.Position); short turnTime = (short)(2 * System.Math.Abs(Npc.Position.Heading - heading) / System.Math.Max(45, System.Math.Max(Npc.NpcTemplate.Shape.TurnSpeed, Npc.NpcTemplate.Shape.WalkSpeed))); if (turnTime > 200 && !MoveController.IsActive) { Global.VisibleService.Send(Npc, new SpDirectionChange(Creature, heading, turnTime)); Npc.Position.Heading = heading; NextChangeDirectionUts = now + turnTime; } else { NextChangeDirectionUts = now + 500; } } return; } Npc.VisiblePlayers.Each( player => { if (PlayerInFocus != null || player.LifeStats.IsDead() || player.Position.DistanceTo(Npc.Position) > agroDistance) { return; } OnCreatureApproached(player); }); }
public override void Init(Creature creature) { base.Init(creature); NextRegenUts = RandomUtilities.GetCurrentMilliseconds() + 1000; NextDistressUts = RandomUtilities.GetCurrentMilliseconds() + 60000; LastBattleUts = 0; }
public void UpdateTarget(Creature creature) { if (Contains(creature)) { lock (TargetsLock) Targets[creature] = RandomUtilities.GetCurrentMilliseconds(); } }
public void Close() { if (_account != null) { _account.LastOnlineUtc = RandomUtilities.GetCurrentMilliseconds(); } Client.Disconnect(); }
public void ProcessDamage(Player player) { if (player.Duel == null) { return; } player.Duel.LastKickUtc = RandomUtilities.GetCurrentMilliseconds(); }
public void Start(Player player) { Player = player; AutoRebirthUts = RandomUtilities.GetCurrentMilliseconds() + 1200000; //30 minutes Player.LifeStats.Kill(); PlayerLogic.PleyerDied(player); }
protected void RandomWalkAction() { if (Npc.Target != null || MoveController.IsActive) { return; } if (Npc.Attack != null && !Npc.Attack.IsFinished) { return; } if (Npc.NpcTemplate.Shape.WalkSpeed <= 0) { return; } if (Npc.Instance.IsEditingMode) { if (Npc.Position.FastDistanceTo(Npc.BindPoint) > 0) { MoveController.MoveTo(Creature.BindPoint); } return; } long now = RandomUtilities.GetCurrentMilliseconds(); if (now - 10000 < LastWalkUts) { return; } LastWalkUts = RandomUtilities.GetCurrentMilliseconds() + Random.Next(5000, 10000); if (Random.Next(0, 100) < 50) { return; } double distanceToBind = Npc.BindPoint.DistanceTo(Creature.Position); if (distanceToBind > 500) { MoveController.MoveTo(Creature.BindPoint); return; } MoveController.MoveTo(Npc.Position.X + Random.Next(150, 300) * (Random.Next(0, 100) < 50 ? 1 : -1) , Npc.Position.Y + Random.Next(150, 300) * (Random.Next(0, 100) < 50 ? 1 : -1)); }
public void ProcessGather() { Gather.CurrentGatherCounter--; if (Gather.CurrentGatherCounter <= 0) { Gather.CurrentGatherCounter = 0; DieUtc = RandomUtilities.GetCurrentMilliseconds(); } }
public override void Action() { if (Player.Controller is DeathController) { return; } if (UsedCampfire != null) { if (UsedCampfire.Instance != Player.Instance || UsedCampfire.Position.FastDistanceTo(Player.Position) > (UsedCampfire.Type == 4 ? 200 : 100)) { UsedCampfire = null; if (Player.PlayerMode == PlayerMode.Relax) { Player.PlayerMode = PlayerMode.Normal; Global.VisibleService.Send(Player, new SpCharacterState(Player)); } } else if (Player.PlayerMode == PlayerMode.Normal) { Player.PlayerMode = PlayerMode.Relax; Global.VisibleService.Send(Player, new SpCharacterState(Player)); } } long now = RandomUtilities.GetCurrentMilliseconds(); if (Player.Controller is BattleController) { LastBattleUts = now; } while (now >= NextRegenUts) { Regenerate(); NextRegenUts += Player.Controller is BattleController ? 5000 : 2000; } while (now > NextDistressUts) { int timeout = (Player.LifeStats.Stamina > 100) ? 90000 : 60000; if (Player.Controller is BattleController) { timeout -= 30000; } Distress(); NextDistressUts += timeout; } }
private bool CanUseItem(Player player, StorageItem item, Player secondPlayer = null, bool sendmessages = false) { int groupId = ItemTemplate.Factory(item.ItemId).CoolTimeGroup; if (item.ItemTemplate.RequiredUserStatus != null && !item.ItemTemplate.RequiredUserStatus.Contains(player.PlayerMode.ToString().ToUpper())) { return(false); } if (player.PlayerLevel < item.ItemTemplate.Level) { if (sendmessages) { SystemMessages.YouMustBeAHigherLevelToUseThat.Send(player.Connection); } return(false); } if (item.ItemTemplate.RequiredSecondCharacter && secondPlayer == null) { return(false); } if (groupId != 0 && player.ItemCoodowns.ContainsKey(groupId) && (RandomUtilities.GetCurrentMilliseconds() - player.ItemCoodowns[groupId]) / 1000 < item.ItemTemplate.Cooltime) { //todo System message return(false); } if (item.ItemTemplate.CombatItemType == CombatItemType.RECIPE && player.Recipes.Contains(item.ItemId)) { if (!Data.Data.Recipes.ContainsKey(item.ItemId)) { Logger.WriteLine(LogState.Warn, "ItemService: Can't find recipe {0}", item.ItemId); return(false); } if (player.Recipes.Contains(item.ItemId)) { //todo System message return(false); } if (player.PlayerCraftStats.GetCraftSkills(Data.Data.Recipes[item.ItemId].CraftStat) < Data.Data.Recipes[item.ItemId].ReqMin) { //todo System message return(false); } } return(true); }
protected static void MainLoop() { while (ServerIsWork) { try { if (RandomUtilities.GetCurrentMilliseconds() - Cache.LastSaveUts > 600000) // Backup Every 10 Min { Cache.LastSaveUts = RandomUtilities.GetCurrentMilliseconds(); Cache.SaveData(); } //Services: FeedbackService.Action(); AccountService.Action(); PlayerService.Action(); MapService.Action(); ChatService.Action(); VisibleService.Action(); ControllerService.Action(); CraftService.Action(); ItemService.Action(); AiService.Action(); GeoService.Action(); StatsService.Action(); ObserverService.Action(); TeleportService.Action(); AreaService.Action(); PartyService.Action(); SkillsLearnService.Action(); GuildService.Action(); DuelService.Action(); //Engines: ActionEngine.Action(); AdminEngine.Action(); SkillEngine.Action(); QuestEngine.Action(); //Others: DelayedAction.CheckActions(); } catch (Exception ex) { Logger.WriteLine(LogState.Exception, "MainLoop: " + ex.Message + " St: " + ex.StackTrace); } Thread.Sleep(10); } }
public override void Init(Creature creature) { base.Init(creature); Projectile = (Projectile)creature; if (Projectile.TargetPosition != null) { MoveController = new NpcMoveController(creature); MoveController.MoveTo(Projectile.TargetPosition); } DieUts = RandomUtilities.GetCurrentMilliseconds() + Projectile.Lifetime; }
private async void StartCondition(Duel duel) { new SpDuelCounter().Send(duel.Initiator); new SpDuelCounter().Send(duel.Initiated); await Task.Delay(5000); duel.LastKickUtc = RandomUtilities.GetCurrentMilliseconds(); Communication.Global.RelationService.ResendRelation(duel.Initiator); Communication.Global.RelationService.ResendRelation(duel.Initiated); lock (DuelsLock) Duels.Add(duel); }
//Actions: public override void Action() { if (Npc.NpcTemplate.IsVillager || Npc.NpcTemplate.IsObject) { return; } long now = RandomUtilities.GetCurrentMilliseconds(); if (Npc.LifeStats.IsDead()) { if (RespawnUts == 0) { CreatureLogic.NpcDied(Npc); RespawnUts = now + 20000; return; } if (now < RespawnUts || Global.MapService.IsDungeon(Npc.Position.MapId)) { return; } RespawnUts = 0; Npc.BindPoint.CopyTo(Npc.Position); MoveController.Reset(); BattleController.Reset(); Npc.LifeStats.Rebirth(); } long elapsed = now - LastCallUts; LastCallUts = now; MoveController.Action(elapsed); BattleController.Action(); //if (Npc.VisiblePlayers.Count < 1) return; EnemiesListenAction(); if (NextChangeDirectionUts < now) { RandomWalkAction(); } }
// public void Action() { if (Effect.TickInterval == 0) { return; } long now = RandomUtilities.GetCurrentMilliseconds(); long nextTick = LastTick + Effect.TickInterval * 1000; if (nextTick < now) { LastTick = nextTick; Tick(); } }
private bool CheckRequirements(Player player, Skill skill) { if (player.PlayerMount != 0 //|| !player.Skills.Contains(skill.BaseId) || player.LifeStats.Hp < skill.Precondition.Cost.Hp ) { SystemMessages.YouCannotUseThatSkillAtTheMoment.Send(player.Connection); return(false); } if (skill.Precondition.CoolTime > 0) { long cooldownUtc = 0; if (!player.SkillCooldowns.ContainsKey(skill.Id)) { player.SkillCooldowns.Add(skill.Id, 0); } else { cooldownUtc = player.SkillCooldowns[skill.Id]; } long now = RandomUtilities.GetCurrentMilliseconds(); if (cooldownUtc > now) { return(false); } player.SkillCooldowns[skill.Id] = now + skill.Precondition.CoolTime; } if (player.LifeStats.Mp < skill.Precondition.Cost.Mp) { SystemMessages.NotEnoughMp.Send(player.Connection); return(false); } return(true); }
public static void SaveData() { Stopwatch stopwatch = Stopwatch.StartNew(); if (RandomUtilities.GetCurrentMilliseconds() - Cache.LastBackupUts > 600000) // Backup Every 10 Min { //removed Cache Backup SaveDir } //save to cachefile using (FileStream fs = File.Create("cache.bin")) Serializer.SerializeWithLengthPrefix(fs, Accounts, PrefixStyle.Fixed32); using (FileStream fs = File.Create("guilds_cache.bin")) Serializer.SerializeWithLengthPrefix(fs, Guilds, PrefixStyle.Fixed32); stopwatch.Stop(); Logger.WriteLine(LogState.Info, "Cache: Saved {0} accounts and {2} guilds in {1}s" , Accounts.Count , (stopwatch.ElapsedMilliseconds / 1000.0).ToString("0.00"), Guilds.Count); }
public void Action() { lock (DuelsLock) { for (int i = 0; i < Duels.Count; i++) { if (RandomUtilities.GetCurrentMilliseconds() - Duels[i].LastKickUtc >= 60000) { Duels[i].Initiator.Duel = null; Duels[i].Initiated.Duel = null; Communication.Global.RelationService.ResendRelation(Duels[i].Initiator); Communication.Global.RelationService.ResendRelation(Duels[i].Initiated); SystemMessages.DuelAutomaticallyEnded.Send(Duels[i].Initiator); SystemMessages.DuelAutomaticallyEnded.Send(Duels[i].Initiated); Duels.RemoveAt(i); i--; } } } }
public void AddTarget(Creature creature) { lock (TargetsLock) { if (Targets == null) { Targets = new Dictionary <Creature, long>(); } if (!Targets.ContainsKey(creature)) { Targets.Add(creature, RandomUtilities.GetCurrentMilliseconds()); if (Targets.Count == 1) { SystemMessages.BattleBegan.Send(Player.Connection); } } else { UpdateTarget(creature); } } }
public override void Action() { if (Projectile.LifeStats.IsDead()) { if (Projectile.VisiblePlayers.Count == 0) { CreatureLogic.ReleaseProjectile(Projectile); } return; } long now = RandomUtilities.GetCurrentMilliseconds(); if (now > DieUts) { Projectile.LifeStats.Kill(); return; } if (MoveController != null) { long elapsed = now - LastCallUts; LastCallUts = now; MoveController.Action(elapsed); } var targets = Global.VisibleService.FindTargets((Creature)Projectile.Parent, Projectile.Position, Projectile.AttackDistance + 40, TargetingAreaType.EnemyOrPvP); if (targets.Count > 0) { Global.SkillEngine.UseProjectileSkill(Projectile); Projectile.LifeStats.Kill(); } }
public void ItemUse(Player player, int itemId, WorldPosition position) { StorageItem i = Global.StorageService.GetItemById(player.Inventory, itemId); if (i == null) { return; } if (!CanUseItem(player, i, null, true)) { return; } if (i.ItemTemplate.Id == 98) //Campfire { if (MapService.TryPutCampfire(player, position)) { Global.StorageService.RemoveItemById(player, player.Inventory, itemId, 1); } return; } ItemTemplate template = i.ItemTemplate; SkillStat skillStat = template.CatigorieStat as SkillStat; if (skillStat == null && template.CombatItemType != CombatItemType.RECIPE) { return; } switch (template.CombatItemType) { case CombatItemType.SKILLBOOK: Global.SkillsLearnService.UseSkillBook(player, template.Id); break; case CombatItemType.IMMEDIATE: case CombatItemType.DISPOSAL: { Global.SkillEngine.UseSkill( player.Connection, new UseSkillArgs { IsItemSkill = true, SkillId = skillStat.SkillId, StartPosition = position, }); new SpItemCooldown(itemId, template.Cooltime).Send(player); } break; case CombatItemType.NO_COMBAT: //new SpSystemNotice("Process use NO_COMBAT item").Send(player.Connection); break; case CombatItemType.RECIPE: Global.CraftService.AddRecipe(player, itemId); SystemMessages.YouLearnedToMakeRecipe("@item:" + itemId); //new SpSystemNotice("You learned new recipe").Send(player.Connection); break; } int groupId = ItemTemplate.Factory(itemId).CoolTimeGroup; if (groupId != 0) { if (player.ItemCoodowns.ContainsKey(groupId)) { player.ItemCoodowns[groupId] = RandomUtilities.GetCurrentMilliseconds(); } else { player.ItemCoodowns.Add(groupId, RandomUtilities.GetCurrentMilliseconds()); } } Global.StorageService.RemoveItemById(player, player.Inventory, itemId, 1); }
public void Action() { try { lock (MapLock) { foreach (var map in Maps.Values) { for (int i = 0; i < map.Count; i++) { for (int j = 0; j < map[i].Npcs.Count; j++) { try { map[i].Npcs[j].Ai.Action(); } // ReSharper disable EmptyGeneralCatchClause catch // ReSharper restore EmptyGeneralCatchClause { //Collection modified } if ((j & 1023) == 0) // 2^N - 1 { Thread.Sleep(1); } } for (int j = 0; j < map[i].Gathers.Count; j++) { try { map[i].Gathers[j].Ai.Action(); } // ReSharper disable EmptyGeneralCatchClause catch // ReSharper restore EmptyGeneralCatchClause { //Collection modified } if ((j & 1023) == 0) // 2^N - 1 { Thread.Sleep(1); } } for (int j = 0; j < map[i].Projectiles.Count; j++) { try { map[i].Projectiles[j].Ai.Action(); } // ReSharper disable EmptyGeneralCatchClause catch // ReSharper restore EmptyGeneralCatchClause { //Collection modified } if ((j & 1023) == 0) // 2^N - 1 { Thread.Sleep(1); } } long now = RandomUtilities.GetCurrentMilliseconds(); for (int j = 0; j < map[i].Campfires.Count; j++) { try { var campfire = map[i].Campfires[j]; if (!campfire.IsStationary && campfire.DespawnUts <= now) { map[i].Campfires.RemoveAt(j--); campfire.VisiblePlayers.Each(player => { try { player.VisibleCampfires.Remove(campfire); } catch { //Already removed } }); Global.VisibleService.Send(campfire, new SpRemoveCampfire(campfire)); campfire.Release(); } } // ReSharper disable EmptyGeneralCatchClause catch // ReSharper restore EmptyGeneralCatchClause { //Collection modified } if ((j & 1023) == 0) // 2^N - 1 { Thread.Sleep(1); } } } } } } // ReSharper disable EmptyGeneralCatchClause catch // ReSharper restore EmptyGeneralCatchClause { //Collection modified } }