private static void UpdateMonsterViewFrustrum(Sprite obj) { //get aislings in range of this object that is not already. var nearByAislings = obj.GetObjects <Aisling>(i => i.WithinRangeOf(obj)); foreach (var nearbyAisling in nearByAislings) { //aisling already has seen this object before, check if it is out of view range if (nearbyAisling.InsideView(obj) && !nearbyAisling.WithinRangeOf(obj)) { //monster has been seen before, but is now out of view //so we must remove it from his view. nearbyAisling.RemoveFromView(obj); //now tell the server to display the remove packet. obj.RemoveFrom(nearbyAisling); //Invoke Onleave if (obj is Monster) { (obj as Monster).Script ?.OnLeave(nearbyAisling?.Client); } } //aisling has not seen this object before. if (!nearbyAisling.InsideView(obj)) { if (nearbyAisling.WithinRangeOf(obj)) { //construct batch var spriteBatch = new List <Sprite>(); //add parent to batch if (!(obj is Aisling)) { //invoke OnApproach if (obj is Monster) { (obj as Monster).Script ?.OnApproach(nearbyAisling?.Client); } spriteBatch.Add(obj); } else if (obj is Aisling) { if (obj.Client.Aisling.Serial != nearbyAisling.Client.Aisling.Serial && !(obj as Aisling).Dead) { if ((obj as Aisling).Flags == AislingFlags.Invisible) { return; } nearbyAisling.Show(Scope.Self, new ServerFormat33(nearbyAisling.Client, obj as Aisling)); } } nearbyAisling.View(obj); //it's still in range. //check if there are any other monsters around this object. //that are also in range of this aisling. var nearParentObj = nearbyAisling.GetObjects( i => i.Serial != obj.Serial && // not the same object obj.WithinRangeOf(i) && //is within range of parent obj nearbyAisling.WithinRangeOf(i), Get.Monsters | Get.Mundanes | Get.Items | Get.Money); //also in range of nearbly aisling //any objects to display in batch? if (nearParentObj.Length > 0) { foreach (var nobj in nearParentObj) { if (nobj is Aisling) { continue; } if (nearbyAisling.InsideView(nobj) && !nearbyAisling.WithinRangeOf(nobj)) { nobj.RemoveFrom(nearbyAisling); continue; } if (!nearbyAisling.InsideView(nobj) && nearbyAisling.WithinRangeOf(nobj)) { if (spriteBatch.FirstOrDefault(i => i.Serial == nobj.Serial) == null) { spriteBatch.Add(nobj); } } } } //check how much packets we need to send. //this makes sure we don't overflow the client //sending to much display packets at once. //so we chunk them up. var blocks = Split(spriteBatch).ToArray(); foreach (var block in blocks) { block.ForEach(i => nearbyAisling.View(i)); var payLoad = new ServerFormat07(block.ToArray()); nearbyAisling.Show( Scope.DefinedAislings, payLoad, nearByAislings); } } } } }
public virtual void Format07Handler(ServerFormat07 format) { }
private static void UpdateMonsterViewFrustrum(Sprite obj) { //get aislings in range of this object that is not already. var nearByAislings = obj.GetObjects <Aisling>(i => i.WithinRangeOf(obj)); foreach (var nearbyAisling in nearByAislings) { //aisling already has seen this object before, check if it is out of view range if (nearbyAisling.InsideView(obj) && !nearbyAisling.WithinRangeOf(obj)) { //monster has been seen before, but is now out of view //so we must remove it from his view. nearbyAisling.RemoveFromView(obj); //now tell the server to display the remove packet. obj.RemoveFrom(nearbyAisling); //Invoke Onleave if (obj is Monster) { (obj as Monster).Script ?.OnLeave(nearbyAisling.Client); } } //aisling has not seen this object before. if (!nearbyAisling.InsideView(obj)) { if (nearbyAisling.WithinRangeOf(obj)) { //construct batch var spriteBatch = new List <Sprite>(); //add parent to batch if (!(obj is Aisling)) { //invoke OnApproach if (obj is Monster) { (obj as Monster).Script ?.OnApproach(nearbyAisling.Client); } spriteBatch.Add(obj); } else { if (obj.Client.Aisling.Serial != nearbyAisling.Client.Aisling.Serial && !(obj as Aisling).Dead) { if ((obj as Aisling).Flags == AislingFlags.Invisible) { return; } nearbyAisling.Show(Scope.Self, new ServerFormat33(nearbyAisling.Client, obj as Aisling)); } } nearbyAisling.View(obj); //check how much packets we need to send. //this makes sure we don't overflow the client //sending to much display packets at once. //so we chunk them up. // var blocks = Split(spriteBatch).ToArray(); var payLoad = new ServerFormat07(spriteBatch.ToArray()); nearbyAisling.Show( Scope.DefinedAislings, payLoad, nearByAislings); foreach (var block in spriteBatch) { nearbyAisling.View(block); } } } } }