protected override void TickCore(Entity host, RealmTime time, ref object state) { ProtectState s; if (state == null) s = ProtectState.DontKnowWhere; else s = (ProtectState) state; Status = CycleStatus.NotStarted; if (host.HasConditionEffect(ConditionEffectIndex.Paralyzed)) return; Entity entity = host.GetNearestEntity(acquireRange, protectee); Vector2 vect; switch (s) { case ProtectState.DontKnowWhere: if (entity != null) { s = ProtectState.Protecting; goto case ProtectState.Protecting; } break; case ProtectState.Protecting: if (entity == null) { s = ProtectState.DontKnowWhere; break; } vect = new Vector2(entity.X - host.X, entity.Y - host.Y); if (vect.Length > reprotectRange) { Status = CycleStatus.InProgress; vect.Normalize(); float dist = host.GetSpeed(speed)*(time.thisTickTimes/1000f); host.ValidateAndMove(host.X + vect.X*dist, host.Y + vect.Y*dist); host.UpdateCount++; } else { Status = CycleStatus.Completed; s = ProtectState.Protected; } break; case ProtectState.Protected: if (entity == null) { s = ProtectState.DontKnowWhere; break; } Status = CycleStatus.Completed; vect = new Vector2(entity.X - host.X, entity.Y - host.Y); if (vect.Length > protectionRange) { s = ProtectState.Protecting; goto case ProtectState.Protecting; } break; } state = s; }
protected override void TickCore(Entity host, RealmTime time, ref object state) { int cool = (int) state; if (cool <= 0) { if (host.HasConditionEffect(ConditionEffectIndex.Stunned)) return; Position target = new Position { X = host.X + (float) (range*Math.Cos(angle.Value)), Y = host.Y + (float) (range*Math.Sin(angle.Value)), }; host.Owner.Timers.Add(new WorldTimer(0, (world, t) => { Entity entity = Entity.Resolve(world.Manager, child); entity.Move(target.X, target.Y); (entity as Enemy).Terrain = (host as Enemy).Terrain; world.EnterWorld(entity); })); cool = coolDown.Next(Random); } else cool -= time.thisTickTimes; state = cool; }
protected override void BehaveCore(BehaviorCondition cond, RealmTime? time, object state) { if (cond == BehaviorCondition.OnDeath) { if (!Host.Self.BagDropped) { var counter = (Host as Enemy).DamageCounter; var dat = counter.GetPlayerData(); var items = new Dictionary<Player, List<Item>>(); ProcessPublicBags(rand, dat); if (Host.Self.Owner.Name == "Battle Arena") { if (rand.Next(1, 5) == 1) { ProcessSoulBags(rand, dat); } } else if (Host.Self.Owner.Name == "Free Battle Arena") { if (rand.Next(1, 15) == 1) { ProcessSoulBags(rand, dat); } } else ProcessSoulBags(rand, dat); Host.Self.BagDropped = true; } } }
public void TickLoop() { log.Info("AutoSave started."); var watch = new Stopwatch(); watch.Start(); var t = new RealmTime(); do { if (Manager.Terminating) break; if (watch.ElapsedMilliseconds % 120000 == 0) { if (Saved) Saved = false; else { foreach (var i in Manager.Clients.Values) { if (i.Player == null || i.Player != null && i.Player.Owner == null) return; i.Save(); } Saved = true; } } } while (true); log.Info("AutoSave stopped."); }
protected override void TickCore(Entity host, RealmTime time, ref object state) { WanderStorage storage; if (state == null) storage = new WanderStorage(); else storage = (WanderStorage)state; Status = CycleStatus.NotStarted; if (host.HasConditionEffect(ConditionEffects.Paralyzed)) return; Status = CycleStatus.InProgress; if (storage.RemainingDistance <= 0) { storage.Direction = new Vector2(Random.Next(-1, 2), Random.Next(-1, 2)); storage.Direction.Normalize(); storage.RemainingDistance = period.Next(Random) / 1000f; Status = CycleStatus.Completed; } float dist = host.GetSpeed(speed) * (time.thisTickTimes / 1000f); host.ValidateAndMove(host.X + storage.Direction.X * dist, host.Y + storage.Direction.Y * dist); host.UpdateCount++; storage.RemainingDistance -= dist; state = storage; }
protected override bool TickCore(RealmTime time) { var dist = range; var player = GetNearestEntity(ref dist, null); if (player != null) { var chr = Host as Character; var target = new Position { X = player.X, Y = player.Y }; chr.Owner.BroadcastPacket(new ShowEffectPacket { EffectType = EffectType.Throw, Color = new ARGB(0xffffbf00), TargetId = Host.Self.Id, PosA = target }, null); chr.Owner.Timers.Add(new WorldTimer(1500, (world, t) => { var entity = Entity.Resolve(objType); entity.Move(target.X, target.Y); (entity as Enemy).Terrain = (chr as Enemy).Terrain; world.EnterWorld(entity); })); } return true; }
protected override void BehaveCore(BehaviorCondition cond, RealmTime? time, object state, string msg, Player player) { if (!adminOnly || player.Client.Account.Rank >= 2) { foreach (var s in chat) { if (msg.ToLower() == s.ToLower()) { foreach (var i in behaves) { i.Tick(Host, (RealmTime)time); } return; } } if (falseBehaves != null) { foreach (var f in falseBehaves) { f.Tick(Host, (RealmTime)time); } } } }
protected override void TickCore(Entity host, RealmTime time, ref object state) { int index; if (state == null) index = -1; else index = (int)state; if (index < 0) //select { index = 0; for (int i = 0; i < children.Length; i++) { children[i].Tick(host, time); if (children[i].Status == CycleStatus.InProgress) { index = i; break; } } } else //run a cycle { children[index].Tick(host, time); if (children[index].Status == CycleStatus.Completed || children[index].Status == CycleStatus.NotStarted) index = -1; } state = index; }
protected override void TickCore(Entity host, RealmTime time, ref object state) { BuzzStorage storage = (BuzzStorage)state; Status = CycleStatus.NotStarted; if (host.HasConditionEffect(ConditionEffects.Paralyzed)) return; if (storage.RemainingTime > 0) { storage.RemainingTime -= time.thisTickTimes; Status = CycleStatus.NotStarted; } else { Status = CycleStatus.InProgress; if (storage.RemainingDistance <= 0) { do { storage.Direction = new Vector2(Random.Next(-1, 2), Random.Next(-1, 2)); } while (storage.Direction.X == 0 && storage.Direction.Y == 0); storage.Direction.Normalize(); storage.RemainingDistance = this.dist; Status = CycleStatus.Completed; } float dist = host.GetSpeed(speed) * (time.thisTickTimes / 1000f); host.ValidateAndMove(host.X + storage.Direction.X * dist, host.Y + storage.Direction.Y * dist); host.UpdateCount++; storage.RemainingDistance -= dist; } state = storage; }
protected override bool TickCore(RealmTime time) { if (Host.Self.HasConditionEffect(ConditionEffects.Stunned)) return false; var chr = Host as Character; var startAngle = angle - projAngle * (numShot - 1) / 2; var desc = chr.ObjectDesc.Projectiles[projectileIndex]; byte prjId = 0; Position prjPos = new Position() { X = chr.X, Y = chr.Y }; var dmg = chr.Random.Next(desc.MinDamage, desc.MaxDamage); for (int i = 0; i < numShot; i++) { var prj = chr.CreateProjectile( desc, chr.ObjectType, dmg, time.tickTimes, prjPos, (float)(startAngle + projAngle * i)); chr.Owner.EnterWorld(prj); if (i == 0) prjId = prj.ProjectileId; } chr.Owner.BroadcastPacket(new MultiShootPacket() { BulletId = prjId, OwnerId = Host.Self.Id, BulletType = (byte)desc.BulletType, Position = prjPos, Angle = (float)startAngle, Damage = (short)dmg, NumShots = (byte)numShot, AngleIncrement = (float)projAngle, }, null); return true; }
protected override void BehaveCore(BehaviorCondition cond, RealmTime? time, object state) { if (Host.Self.Owner.Name != "Battle Arena" && Host.Self.Owner.Name != "Free Battle Arena") { if (new Random().Next(1, 100) <= percent) { var entity = Entity.Resolve(objType) as Portal; var parent = Host as Entity; entity.Move(parent.X, parent.Y); parent.Owner.EnterWorld(entity); var w = RealmManager.GetWorld(Host.Self.Owner.Id); w.Timers.Add(new WorldTimer(timeExist*1000, (world, t) => { if (timeExist > 0) try { w.LeaveWorld(entity); } catch { } })); } } }
protected override bool TickCore(RealmTime time) { var chr = Host as Character; var target = new Position { X = Host.Self.X, Y = Host.Self.Y }; target.X += (float) Math.Cos(angle)*range; target.Y += (float) Math.Sin(angle)*range; chr.Owner.BroadcastPacket(new ShowEffectPacket { TargetId = Host.Self.Id, PosA = target }, null); chr.Owner.Timers.Add(new WorldTimer(1500, (world, t) => { var entity = Entity.Resolve(objType); entity.Move(target.X, target.Y); (entity as Enemy).Terrain = (chr as Enemy).Terrain; world.EnterWorld(entity); })); return true; }
protected override bool TickCore(RealmTime time) { int remainingTick; object o; if (!Host.StateStorage.TryGetValue(Key, out o)) remainingTick = 0; else remainingTick = (int)o; remainingTick -= time.thisTickTimes; bool ret; if (remainingTick <= 0) { if (CountEntity(radius, objType) < maxCount) { Entity entity = Entity.Resolve(objType); entity.Move(Host.Self.X, Host.Self.Y); (entity as Enemy).Terrain = (Host as Enemy).Terrain; Host.Self.Owner.EnterWorld(entity); } remainingTick = rand.Next(minTick, maxTick); ret = true; } else ret = false; Host.StateStorage[Key] = remainingTick; return ret; }
protected override bool TickCore(RealmTime time) { if (Host.Self.HasConditionEffect(ConditionEffects.Paralyzed)) return true; var speed = this.speed * GetSpeedMultiplier(Host.Self); float dist = radius; Entity entity = GetNearestEntity(ref dist, objType); Character chr = Host as Character; if (entity != null && chr.HP < threshold) { var x = Host.Self.X; var y = Host.Self.Y; Vector2 vect = new Vector2(entity.X, entity.Y) - new Vector2(Host.Self.X, Host.Self.Y); vect.Normalize(); vect *= -1 * (speed / 1.5f) * (time.thisTickTimes / 1000f); ValidateAndMove(Host.Self.X + vect.X, Host.Self.Y + vect.Y); Host.Self.UpdateCount++; if (!Host.StateStorage.ContainsKey(Key)) { chr.Owner.BroadcastPacket(new ShowEffectPacket() { EffectType = EffectType.Flashing, PosA = new Position() { X = 1, Y = 1000000 }, TargetId = chr.Id, Color = new ARGB(0xff303030) }, null); Host.StateStorage[Key] = true; } return true; } else return false; }
protected override void OnStateEntry(Entity host, RealmTime time, ref object state) { Entity[] ens = host.GetNearestEntities(dist).ToArray(); foreach (Entity e in ens) if (e.ObjectType == host.Manager.GameData.IdToObjectType[children]) host.Owner.LeaveWorld(e); }
protected override void TickCore(Entity host, RealmTime time, ref object state) { condition.Tick(host, time); if (condition.Result) foreach (var i in behaviors) i.Tick(host, time); }
protected override bool TickCore(RealmTime time) { var radius = dist; var entity = GetNearestEntityPet(ref radius) as Enemy; if (entity != null) { entity.Owner.BroadcastPacket(new ShowEffectPacket { EffectType = EffectType.Potion, TargetId = entity.Id, Color = new ARGB(0xFF0000) }, null); entity.Owner.BroadcastPacket(new ShowEffectPacket { EffectType = EffectType.Trail, TargetId = Host.Self.Id, PosA = new Position {X = entity.X, Y = entity.Y}, Color = new ARGB(0xFF0000) }, null); entity.Damage(Host.Self.PlayerOwner, time, new Random().Next(lowest, highest), false, new ConditionEffect[] {}); } return false; }
protected override bool TickCore(RealmTime time) { var radius = dist; var entity = GetNearestEntityPet(ref radius) as Enemy; if (entity != null) { entity.Owner.BroadcastPacket(new ShowEffectPacket { EffectType = EffectType.AreaBlast, Color = new ARGB(0x3E3A78), TargetId = entity.Id, PosA = new Position { X = 1 } }, null); entity.Owner.BroadcastPacket(new ShowEffectPacket { EffectType = EffectType.Trail, TargetId = Host.Self.Id, PosA = new Position { X = entity.X, Y = entity.Y }, Color = new ARGB(0x3E3A78) }, null); entity.Damage(Host.Self.PlayerOwner, time, 35, false); } return false; }
protected override bool TickCore(RealmTime time) { if (Host.Self.HasConditionEffect(ConditionEffects.Paralyzed)) return true; var speed = this.speed * GetSpeedMultiplier(Host.Self); WanderingState state; object o; if (!Host.StateStorage.TryGetValue(Key, out o)) Host.StateStorage[Key] = state = new WanderingState(); else { state = (WanderingState)o; var dist = speed / 1.5f * (time.thisTickTimes / 1000f); state.remainingDist -= dist; ValidateAndMove(Host.Self.X + state.x * dist, Host.Self.Y + state.y * dist); Host.Self.UpdateCount++; } bool ret; if (state.remainingDist <= 0) { state.x = rand.Next(-1, 2); state.y = rand.Next(-1, 2); state.remainingDist = dist + dist * (float)(rand.NextDouble() * 0.1 - 0.05); ret = true; } else ret = false; return ret; }
public void PlayerText(RealmTime time, PlayerTextPacket pkt) { if (pkt.Text[0] == '/') { string[] x = pkt.Text.Trim().Split(' '); if (x.Length > 1) { AnnounceText = pkt.Text.Substring(10); } ChatMessage = pkt.Text; string[] z = pkt.Text.Trim().Split('|'); y = z.Skip(1).ToArray(); ProcessCmd(x[0].Trim('/'), x.Skip(1).ToArray()); } else Owner.BroadcastPacket(new TextPacket() { Name = Name, ObjectId = Id, Stars = Stars, BubbleTime = 5, Recipient = "", Text = pkt.Text, CleanText = pkt.Text }, null); }
protected override bool TickCore(RealmTime time) { Behavior behav = RingAttack.Instance(arms, 0, offsetIncrement * (float)Math.PI / 180 * incrementMultiplier, projectileIndex); int remainingTick; object o; if (!Host.StateStorage.TryGetValue(Key, out o)) remainingTick = rand.Next(0, cooldown); else remainingTick = (int)o; remainingTick -= time.thisTickTimes; bool ret; if (remainingTick <= 0) { if (behav != null) behav.Tick(Host, time); if (behav != null) incrementMultiplier += 1; remainingTick = rand.Next((int)(cooldown * 0.95), (int)(cooldown * 1.05)); ret = true; } else ret = false; Host.StateStorage[Key] = remainingTick; return ret; }
protected override void TickCore(Entity host, RealmTime time, ref object state) { int cooldown; if (state == null) cooldown = 1000; else cooldown = (int)state; Status = CycleStatus.NotStarted; if (host.HasConditionEffect(ConditionEffects.Paralyzed)) return; var player = (Player)host.GetNearestEntity(distance, null); if (player != null) { Vector2 vect; vect = new Vector2(player.X - host.X, player.Y - host.Y); vect.Normalize(); float dist = host.GetSpeed(speed) * (time.thisTickTimes / 1000f); host.ValidateAndMove(host.X + (-vect.X) * dist, host.Y + (-vect.Y) * dist); host.UpdateCount++; if (cooldown <= 0) { Status = CycleStatus.Completed; cooldown = 1000; } else { Status = CycleStatus.InProgress; cooldown -= time.thisTickTimes; } } state = cooldown; }
protected override bool TickCore(RealmTime time) { var radius = dist; var entity = GetNearestEntityPet(ref radius) as Enemy; if (entity != null) { entity.Owner.BroadcastPacket(new ShowEffectPacket { EffectType = EffectType.AreaBlast, Color = new ARGB(0x003298), TargetId = entity.Id, PosA = new Position { X = 1 } }, null); entity.Owner.BroadcastPacket(new ShowEffectPacket { EffectType = EffectType.Trail, TargetId = Host.Self.Id, PosA = new Position { X = entity.X, Y = entity.Y }, Color = new ARGB(0x003298) }, null); entity.ApplyConditionEffect(new ConditionEffect { Effect = ConditionEffectIndex.Paralyzed, DurationMS = 5000 }); } return false; }
protected override bool TickCore(RealmTime time) { float dist = 8; var entity = GetNearestEntityByGroup(ref dist, "Golem"); if (entity != null && dist > 4) { ValidateAndMove(entity.X, entity.Y); Host.StateStorage[Key] = 30*1000; return true; } if (entity == null) { int remainingTick; object obj; if (!Host.StateStorage.TryGetValue(Key, out obj)) remainingTick = 30*1000; else remainingTick = (int) obj; remainingTick -= time.thisTickTimes; if (remainingTick <= 0) Host.Self.Owner.LeaveWorld(Host.Self); Host.StateStorage[Key] = remainingTick; return false; } Host.StateStorage[Key] = 30*1000; return true; }
protected override void TickCore(Entity host, RealmTime time, ref object state) { Pet pet; if (!isValidPet(host, out pet)) return; if (Pet == null) Pet = pet; TickCore(pet, time, ref state); }
protected override bool TickCore(RealmTime time) { if (Host.Self.HasConditionEffect(ConditionEffects.Paralyzed)) return true; var speed = this.speed*GetSpeedMultiplier(Host.Self); var dist = radius; var entity = GetNearestEntity(ref dist, objType); if (entity != null && dist > targetRadius) { var tx = entity.X + rand.Next(-2, 2)/2f; var ty = entity.Y + rand.Next(-2, 2)/2f; if (tx != Host.Self.X || ty != Host.Self.Y) { var x = Host.Self.X; var y = Host.Self.Y; var vect = new Vector2(tx, ty) - new Vector2(Host.Self.X, Host.Self.Y); vect.Normalize(); vect *= (speed/1.5f)*(time.thisTickTimes/1000f); ValidateAndMove(Host.Self.X + vect.X, Host.Self.Y + vect.Y); Host.Self.UpdateCount++; } return true; } return false; }
protected override bool TickCore(RealmTime time) { if (Host.Self.HasConditionEffect(ConditionEffects.Paralyzed)) return true; var speed = this.speed * GetSpeedMultiplier(Host.Self); float d; object o; if (!Host.StateStorage.TryGetValue(Key, out o)) Host.StateStorage[Key] = d = dist; else { d = (float)o; float dd = (speed / 1.5f) * (time.thisTickTimes / 1000f); d -= dd; ValidateAndMove(Host.Self.X + (float)Math.Cos(angle) * dd, Host.Self.Y + (float)Math.Sin(angle) * dd); Host.Self.UpdateCount++; } bool ret; if (d <= 0) { d = dist; ret = true; } else ret = false; Host.StateStorage[Key] = d; return ret; }
protected override void TickCore(Entity host, RealmTime time, ref object state) { if (!returned) { if (host.HasConditionEffect(ConditionEffectIndex.Paralyzed)) return; var spd = host.GetSpeed(speed) * (time.thisTickTimes / 1000f); Position pos = (host as Enemy).SpawnPoint; var tx = pos.X; var ty = pos.Y; if (Math.Abs(tx - host.X) > 1 || Math.Abs(ty - host.Y) > 1) { var x = host.X; var y = host.Y; Vector2 vect = new Vector2(tx, ty) - new Vector2(host.X, host.Y); vect.Normalize(); vect *= spd; host.Move(host.X + vect.X, host.Y + vect.Y); host.UpdateCount++; } if (host.X == pos.X && host.Y == pos.Y && once) { once = true; returned = true; } } }
protected override void TickCore(Entity host, RealmTime time, ref object state) { int cool = (int)state; if (cool <= 0) { if (host.HasConditionEffect(ConditionEffects.Stunned)) return; Position target = new Position() { X = host.X + (float)(range * Math.Cos(angle.Value)), Y = host.Y + (float)(range * Math.Sin(angle.Value)), }; host.Owner.BroadcastPacket(new ShowEffectPacket() { EffectType = EffectType.Throw, Color = new ARGB(0xffffbf00), TargetId = host.Id, PosA = target }, null); host.Owner.Timers.Add(new WorldTimer(1500, (world, t) => { Entity entity = Entity.Resolve(child); entity.Move(target.X, target.Y); (entity as Enemy).Terrain = (host as Enemy).Terrain; world.EnterWorld(entity); })); cool = coolDown.Next(Random); } else cool -= time.thisTickTimes; state = cool; }
protected override bool TickCore(RealmTime time) { object obj; int t; if (Host.StateStorage.TryGetValue(Key, out obj)) t = (int)obj; else t = this.time; bool ret; if (t == this.time) { Host.Self.Owner.BroadcastPacket(new ShowEffectPacket { EffectType = EffectType.Flashing, PosA = new Position { X = this.time / 1000f, Y = 1 }, TargetId = Host.Self.Id, Color = new ARGB(color) }, null); ret = false; t -= time.thisTickTimes; } else if (t < 0) { ret = true; t = this.time; } else { ret = false; t -= time.thisTickTimes; } Host.StateStorage[Key] = t; return ret; }
private void TickState(RealmTime time) { State s; if (stateEntry) { //State entry s = CurrentState; while (s != null && s != stateEntryCommonRoot) { foreach (var i in s.Behaviors) { i.OnStateEntry(this, time); } foreach (var i in s.Transitions) { i.OnStateEntry(this, time); } s = s.Parent; } stateEntryCommonRoot = null; stateEntry = false; } var origState = CurrentState; var state = CurrentState; var transited = false; while (state != null) { if (!transited) { if (state.Transitions.Any(i => i.Tick(this, time))) { transited = true; } } foreach (var i in state.Behaviors.TakeWhile(i => Owner != null)) { i.Tick(this, time); } if (Owner == null) { break; } state = state.Parent; } if (!transited) { return; } //State exit s = origState; while (s != null && s != stateEntryCommonRoot) { foreach (var i in s.Behaviors) { i.OnStateExit(this, time); } s = s.Parent; } }
public TimeEventArgs(RealmTime time) { Time = time; }
public void TickLoop() { log.Info("Logic loop started."); Stopwatch watch = new Stopwatch(); long dt = 0; long count = 0; watch.Start(); RealmTime t = new RealmTime(); do { if (Manager.Terminating) { break; } long times = dt / MsPT; dt -= times * MsPT; times++; long b = watch.ElapsedMilliseconds; count += times; if (times > 3) { log.Warn("LAGGED!| time:" + times + " dt:" + dt + " count:" + count + " time:" + b + " tps:" + count / (b / 1000.0)); } t.tickTimes = b; t.tickCount = count; t.thisTickCounts = (int)times; t.thisTickTimes = (int)(times * MsPT); foreach (ConcurrentQueue <Action <RealmTime> > i in pendings) { Action <RealmTime> callback; while (i.TryDequeue(out callback)) { try { callback(t); } catch (Exception ex) { log.Error(ex); } } } TickWorlds1(t); Manager.InterServer.Tick(t); Player[] tradingPlayers = TradeManager.TradingPlayers.Where(_ => _.Owner == null).ToArray(); foreach (var player in tradingPlayers) { TradeManager.TradingPlayers.Remove(player); } KeyValuePair <Player, Player>[] requestPlayers = TradeManager.CurrentRequests.Where(_ => _.Key.Owner == null || _.Value.Owner == null).ToArray(); foreach (var players in requestPlayers) { TradeManager.CurrentRequests.Remove(players); } //string[] accIds = Manager.Clients.Select(_ => _.Value.Account.AccountId).ToArray(); //List<string> curGStructAccIds = new List<string>(); //foreach(var i in GuildManager.CurrentManagers.Values) // curGStructAccIds.AddRange(i.GuildStructs.Select(_ => _.Key)); //foreach (var i in curGStructAccIds) // if (!accIds.Contains(i)) // GuildManager.RemovePlayerWithId(i); //var m = GuildManager.CurrentManagers; //try //{ // foreach (var g in m) // if (g.Value.Count == 0) // GuildManager.CurrentManagers.Remove(g.Key); //} //catch (Exception ex) //{ // log.Error(ex); //} Thread.Sleep(MsPT); dt += Math.Max(0, watch.ElapsedMilliseconds - b - MsPT); } while (true); log.Info("Logic loop stopped."); }
public virtual void Tick(RealmTime time) { try { if (IsLimbo) { return; } for (var i = 0; i < Timers.Count; i++) { try { if (Timers[i] == null) { continue; } if (!Timers[i].Tick(this, time)) { continue; } Timers.RemoveAt(i); i--; } catch { // ignored } } foreach (var i in Players) { i.Value.Tick(time); } foreach (var i in Pets) { i.Value.Tick(time); } if (EnemiesCollision != null) { foreach (var i in EnemiesCollision.GetActiveChunks(PlayersCollision)) { i.Tick(time); } foreach (var i in StaticObjects.Where(x => x.Value is Decoy)) { i.Value.Tick(time); } } else { foreach (var i in Enemies) { i.Value.Tick(time); } foreach (var i in StaticObjects) { i.Value.Tick(time); } } foreach (var i in Projectiles) { i.Value.Tick(time); } if (Players.Count != 0 || !canBeClosed || !IsDungeon()) { return; } var vault = this as Vault; if (vault != null) { Manager.RemoveVault(vault.AccountId); } Manager.RemoveWorld(this); } catch (Exception e) { Log.Error("World: " + Name + "\n" + e); } }
public void TickLoop() { Log.Info("Logic loop started."); var watch = new Stopwatch(); long dt = 0; long count = 0; watch.Start(); var t = new RealmTime(); do { if (_manager.Terminating) { break; } long times = dt / MsPT; dt -= times * MsPT; times++; long b = watch.ElapsedMilliseconds; count += times; if (times > 3) { Log.Warn("LAGGED!| time:" + times + " dt:" + dt + " count:" + count + " time:" + b + " tps:" + count / (b / 1000.0)); } t.TotalElapsedMs = b; t.TickCount = count; t.TickDelta = (int)times; t.ElaspedMsDelta = (int)(times * MsPT); long c = watch.ElapsedMilliseconds; foreach (var client in _manager.Clients.Keys) { if (client.Player != null && client.Player.Owner != null) { client.Player.Flush(); } //client.SendTick(); } foreach (var i in _pendings) { Action <RealmTime> callback; while (i.TryDequeue(out callback)) { try { callback(t); } catch (Exception e) { Log.Error(e); } } } long dc = watch.ElapsedMilliseconds - c; TickWorlds1(t); _manager.InterServer.Tick(t.ElaspedMsDelta); Thread.Sleep(Math.Max(0, MsPT - (int)dc)); dt += Math.Max(0, watch.ElapsedMilliseconds - b - MsPT); } while (true); Log.Info("Logic loop stopped."); }
public TimeEventArgs(RealmTime time) { this.Time = time; }
public virtual void Tick(RealmTime time) { if (IsLimbo) { return; } if (disposable) { if (Players.Count <= 0 && !isDisposing) { isDisposing = true; if (RemovalMS < 25000) { // log.WarnFormat("World \"{0}\" does not have a valid RemovalMS: {1}! Please allow at least 25 seconds. Default: 25000 ms", Name, RemovalMS); RemovalMS = 25000; } // log.InfoFormat("World {0}, ID:{1} is unused and will dispose in {2}MS.", Name, Id, RemovalMS); WorldTimer timer = new WorldTimer(RemovalMS, (w, t) => { manager.RemoveWorld(w); }); Timers.Add(timer); } else if (isDisposing && Players.Count >= 1) { isDisposing = false; // log.InfoFormat("World {0}, ID:{1} is in use and has cancelled disposal.", Name, Id); } } if (Timers != null && Timers.Count > 0) { for (int i = 0; i < Timers.Count; i++) { if (Timers[i].Tick(this, time) && Timers.Count > 0) { Timers.RemoveAt(i); i--; } } } try //entity ticking now, possible huge range of issues that i can't yet remove the try catch - jade { foreach (var i in Players) { i.Value.Tick(time); } if (isDisposing) { return; } if (EnemiesCollision != null) { foreach (Entity i in EnemiesCollision.GetActiveChunks(PlayersCollision)) { i.Tick(time); } foreach (var i in StaticObjects.Where(x => x.Value is Decoy)) { i.Value.Tick(time); } } else { foreach (var i in Enemies) { i.Value.Tick(time); } foreach (var i in StaticObjects) { i.Value.Tick(time); } } foreach (var i in Projectiles) { i.Value.Tick(time); } } catch (Exception e) { log.Error(e); } }
public void TickState(RealmTime time) { if (_stateEntry) { //State entry var s = CurrentState; while (s != null && s != _stateEntryCommonRoot) { foreach (var i in s.Behaviors) { i.OnStateEntry(this, time); } s = s.Parent; } _stateEntryCommonRoot = null; _stateEntry = false; } var origState = CurrentState; var state = CurrentState; bool transited = false; while (state != null) { if (!transited) { foreach (var i in state.Transitions) { if (i.Tick(this, time)) { transited = true; break; } } } foreach (var i in state.Behaviors) { if (Owner == null) { break; } i.Tick(this, time); } if (Owner == null) { break; } state = state.Parent; } if (transited) { //State exit var s = origState; while (s != null && s != _stateEntryCommonRoot) { foreach (var i in s.Behaviors) { i.OnStateExit(this, time); } s = s.Parent; } } }