public override void ExecuteCommand(ICharacter character, Identity target, string[] args) { if ((character.Stats[StatIds.externaldoorinstance].Value == 0) || (character.Stats[StatIds.externalplayfieldinstance].Value == 0)) { ChatTextMessageHandler.Default.Create(character, "Please enter a proxyfied playfield first."); } Coordinate tempCoordinate = character.Coordinates(); PlayfieldData pfData = PlayfieldLoader.PFData[character.Playfield.Identity.Instance]; StatelData o = null; foreach (StatelData s in pfData.Statels) { if (o == null) { o = s; } else { if (Coordinate.Distance2D(tempCoordinate, s.Coord()) < Coordinate.Distance2D(tempCoordinate, o.Coord())) { o = s; } } } if (o == null) { ChatTextMessageHandler.Default.Create( character, "No statel on this playfield... Very odd, where exactly are you???"); } else { DBTeleport tel = new DBTeleport(); tel.playfield = character.Stats[StatIds.externalplayfieldinstance].Value; tel.statelType = 0xc748; // Door only for now tel.statelInstance = character.Stats[StatIds.externaldoorinstance].BaseValue; tel.destinationPlayfield = o.PlayfieldId; tel.destinationType = (int)o.Identity.Type; tel.destinationInstance = BitConverter.ToUInt32(BitConverter.GetBytes(o.Identity.Instance), 0); var temp = TeleportDao.Instance.GetWhere(new { tel.playfield, tel.statelType, tel.statelInstance }); foreach (var t in temp) { TeleportDao.Instance.Delete(t.Id); } TeleportDao.Instance.Add(tel); character.Playfield.Publish( ChatTextMessageHandler.Default.CreateIM(character, "Proxy saved")); } }
/// <summary> /// </summary> /// <param name="fname"> /// </param> /// <returns> /// </returns> public static int CacheAllPlayfieldData(string fname) { PFData = new Dictionary <int, PlayfieldData>(); MessagePackZip.UncompressData <PlayfieldData>(fname).ForEach(x => PFData.Add(x.PlayfieldId, x)); Console.WriteLine("Tweaking in some Statel functions"); // Now lets do some tweaking foreach (PlayfieldData pfd in PFData.Values) { foreach (StatelData sd in pfd.Statels) { bool foundproxyteleport = false; int playfieldid = 0; int doorinstance = 0; foreach (Event ev in sd.Events) { foreach (Function f in ev.Functions) { if (f.FunctionType == (int)FunctionType.TeleportProxy) { foundproxyteleport = true; playfieldid = f.Arguments.Values[1].AsInt32(); doorinstance = (int) ((uint)0xC0000000 | f.Arguments.Values[1].AsInt32() | (f.Arguments.Values[2].AsInt32() << 16)); DBTeleport teleporter = TeleportDao.Instance.GetWhere(new { statelInstance = (uint)sd.Identity.Instance }) .FirstOrDefault(); if (teleporter != null) { doorinstance = (int)teleporter.destinationInstance; f.Arguments.Values[2] = new MessagePackObject(((doorinstance >> 16) & 0xff)); } break; } if (f.FunctionType == (int)FunctionType.TeleportProxy2) { playfieldid = f.Arguments.Values[1].AsInt32(); doorinstance = (int) ((uint)0xC0000000 | f.Arguments.Values[1].AsInt32() | (f.Arguments.Values[2].AsInt32() << 16)); DBTeleport teleporter = TeleportDao.Instance.GetWhere(new { statelInstance = (uint)sd.Identity.Instance }) .FirstOrDefault(); if (teleporter != null) { doorinstance = (int)teleporter.destinationInstance; f.Arguments.Values[2] = new MessagePackObject(((doorinstance >> 16) & 0xff)); } } } if (foundproxyteleport) { break; } } if (ItemLoader.ItemList.ContainsKey(sd.TemplateId)) { if (ItemLoader.ItemList[sd.TemplateId].WantsCollision() && !ItemLoader.ItemList[sd.TemplateId].StatelCollisionDisabled() && (sd.Events.All(x => x.EventType != EventType.OnCollide)) && sd.Events.Any(x => x.EventType == EventType.OnUse)) { Event ev = sd.Events.First(x => x.EventType == EventType.OnUse).Copy(); ev.EventType = EventType.OnCollide; sd.Events.Add(ev); } } if (foundproxyteleport) { if (PFData.ContainsKey(playfieldid)) { StatelData internalDoor = PFData[playfieldid].GetDoor(doorinstance); if (internalDoor != null) { if (internalDoor.Events.All(x => x.EventType != EventType.OnEnter)) { Event ev = new Event(); ev.EventType = EventType.OnEnter; ev.Functions.Add( new Function() { FunctionType = (int)FunctionType.ExitProxyPlayfield }); internalDoor.Events.Add(ev); } } } } } } return(PFData.Count); }
public override void ExecuteCommand(ICharacter character, Identity target, string[] args) { var proxies = TeleportDao.Instance.GetAll(); List <StatelData> statels = new List <StatelData>(); Function lastFound = null; foreach (PlayfieldData pf in PlayfieldLoader.PFData.Values) { bool isProxy = false; foreach (StatelData sd in pf.Statels) { lastFound = null; isProxy = false; if (sd.Events.Count > 0) { foreach (Event e in sd.Events) { foreach (Function f in e.Functions) { if (f.FunctionType == (int)FunctionType.TeleportProxy) { isProxy = true; lastFound = f; if (f.Arguments.Values[1].AsInt32() < 0) { lastFound = null; isProxy = false; } break; } } if (isProxy) { break; } } } if (isProxy) { if ( !proxies.Any( x => (x.statelType == (int)sd.Identity.Type) && (x.statelInstance == (uint)sd.Identity.Instance) && (x.playfield == sd.PlayfieldId))) { PlayfieldData dest = PlayfieldLoader.PFData[lastFound.Arguments.Values[1].AsInt32()]; if (dest.Statels.Count(x => x.Identity.Type == IdentityType.Door) == 1) { StatelData sddest = dest.Statels.First(x => x.Identity.Type == IdentityType.Door); DBTeleport tel = new DBTeleport(); tel.playfield = sd.PlayfieldId; tel.statelType = 0xc748; // Door only for now tel.statelInstance = (uint)sd.Identity.Instance; tel.destinationPlayfield = sddest.PlayfieldId; tel.destinationType = (int)sddest.Identity.Type; tel.destinationInstance = BitConverter.ToUInt32(BitConverter.GetBytes(sddest.Identity.Instance), 0); var temp = TeleportDao.Instance.GetWhere(new { tel.playfield, tel.statelType, tel.statelInstance }); foreach (var t in temp) { TeleportDao.Instance.Delete(t.Id); } TeleportDao.Instance.Add(tel); isProxy = false; } } } if (isProxy) { // Check against proxies already found if ( !proxies.Any( x => (x.statelType == (int)sd.Identity.Type) && (x.statelInstance == (uint)sd.Identity.Instance) && (x.playfield == sd.PlayfieldId))) { PlayfieldData dest = PlayfieldLoader.PFData[lastFound.Arguments.Values[1].AsInt32()]; StatelData door1 = null; if (dest.Statels.Count(x => x.Identity.Type == IdentityType.Door) > 0) { door1 = dest.Statels.First(x => x.Identity.Type == IdentityType.Door); LogUtil.Debug(DebugInfoDetail.Error, sd.PlayfieldId + " " + sd.Identity.ToString(true)); character.Stats[StatIds.externaldoorinstance].BaseValue = (uint)sd.Identity.Instance; character.Stats[StatIds.externalplayfieldinstance].BaseValue = (uint)sd.PlayfieldId; character.Playfield.Teleport( (Dynel)character, new Coordinate(door1.X, door1.Y + 1.0f, door1.Z), character.Heading, new Identity() { Type = (IdentityType)lastFound.Arguments.Values[0].AsInt32(), Instance = door1.PlayfieldId }); return; } LogUtil.Debug(DebugInfoDetail.Error, sd.PlayfieldId + " " + sd.Identity.ToString(true)); character.Stats[StatIds.externaldoorinstance].BaseValue = 0; character.Stats[StatIds.externalplayfieldinstance].BaseValue = 0; character.Playfield.Teleport( (Dynel)character, new Coordinate(sd.X, sd.Y, sd.Z), character.Heading, new Identity() { Type = IdentityType.Playfield, Instance = sd.PlayfieldId }); return; } } } } }