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 OnStateEntry(Entity host, RealmTime time, ref object state) { if (!isMapPosition) { X = baseX + host.X; Y = baseY + host.Y; } else { X = baseX; Y = baseY; } if (instant) { host.Move(X, Y); host.UpdateCount++; } }
protected override void TickCore(Entity host, RealmTime time, ref object state) { if (host is Pet) if ((host as Pet).PlayerOwner != null) return; WmapTile tile = host.Owner.Map[(int)host.X, (int)host.Y].Clone(); if (tile.Region == TileRegion.None && host.Owner is PetYard) { Position pos = (host as Pet).SpawnPoint; host.Move(pos.X, pos.Y); return; } if (host.GetNearestEntity(1, null) == null) { WanderStorage storage; if (state == null) storage = new WanderStorage(); else storage = (WanderStorage)state; Status = CycleStatus.NotStarted; if (host.HasConditionEffect(ConditionEffectIndex.Paralyzed)) return; Status = CycleStatus.InProgress; if (storage.RemainingDistance <= 0) { storage.Direction = new Vector2(Random.Next(-2, 2), Random.Next(-2, 2)); storage.Direction.Normalize(); storage.RemainingDistance = coolDown.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 void TickCore(Entity host, RealmTime time, ref object state) { if (instant) return; if (!returned) { if (host.HasConditionEffect(ConditionEffectIndex.Paralyzed)) return; var spd = host.GetSpeed(speed) * (time.thisTickTimes / 1000f); if (Math.Abs(X - host.X) > 0.5 || Math.Abs(Y - host.Y) > 0.5) { Vector2 vect = new Vector2(X, Y) - 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 == X && host.Y == Y && once) { once = true; returned = true; } } } }
protected override void TickCore(Entity host, RealmTime time, ref object state) { FollowState s; if (state == null) s = new FollowState(); else s = (FollowState)state; Status = CycleStatus.NotStarted; Player player = host.GetPlayerOwner(); if (player.Owner == null) { host.Owner.LeaveWorld(host); return; } Vector2 vect; switch (s.State) { case F.DontKnowWhere: if (s.RemainingTime > 0) s.RemainingTime -= time.thisTickTimes; else s.State = F.Acquired; break; case F.Acquired: if (player == null) { s.State = F.DontKnowWhere; s.RemainingTime = 0; break; } if (s.RemainingTime > 0) s.RemainingTime -= time.thisTickTimes; vect = new Vector2(player.X - host.X, player.Y - host.Y); if (vect.Length > 20) { host.Move(player.X, player.Y); host.UpdateCount++; } else if (vect.Length > 1) { float dist = host.GetSpeed(1.2f) * (time.thisTickTimes / 1000f); if (vect.Length > 2) dist = host.GetSpeed(1.2f + ((float)player.Stats[4] / 100)) * (time.thisTickTimes / 1000f); else if (vect.Length > 3.5) dist = host.GetSpeed(1.2f + ((float)player.Stats[4] + (float)player.Boost[4] / 100)) * (time.thisTickTimes / 1000f); else if (vect.Length > 5) dist = host.GetSpeed(1.3f + ((float)player.Stats[4] + (float)player.Boost[4] / 100)) * (time.thisTickTimes / 1000f); else if (vect.Length > 6) dist = host.GetSpeed(1.4f + ((float)player.Stats[4] + (float)player.Boost[4] / 100)) * (time.thisTickTimes / 1000f); else if (vect.Length > 7) dist = host.GetSpeed(1.5f + ((float)player.Stats[4] + (float)player.Boost[4] / 100)) * (time.thisTickTimes / 1000f); Status = CycleStatus.InProgress; vect.X -= Random.Next(-2, 2) / 2f; vect.Y -= Random.Next(-2, 2) / 2f; vect.Normalize(); host.ValidateAndMove(host.X + vect.X * dist, host.Y + vect.Y * dist); host.UpdateCount++; } break; } state = s; }
public static bool ValidateAndMove(Entity entity, float x, float y) { if (entity.Owner == null || entity.HasConditionEffect(ConditionEffects.Paralyzed)) return false; if (Validate(entity, x, y)) entity.Move(x, y); else if (Validate(entity, entity.X, y)) entity.Move(entity.X, y); else if (Validate(entity, x, entity.Y)) entity.Move(x, entity.Y); else return false; return true; }
protected override void TickCore(Entity host, RealmTime time, ref object state) { if ((host as Pet)?.PlayerOwner == null) return; var pet = (Pet)host; FollowState s; if (state == null) s = new FollowState(); else s = (FollowState)state; Status = CycleStatus.NotStarted; var player = host.GetEntity(pet.PlayerOwner.Id) as Player; if (player == null) { var tile = host.Owner.Map[(int)host.X, (int)host.Y].Clone(); if (tile.Region != TileRegion.PetRegion) { if (!(host.Owner is PetYard)) { host.Owner.LeaveWorld(host); return; } if (tile.Region != TileRegion.Spawn) { host.Owner.LeaveWorld(host); return; } } } switch (s.State) { case F.DontKnowWhere: if (s.RemainingTime > 0) s.RemainingTime -= time.thisTickTimes; else s.State = F.Acquired; break; case F.Acquired: if (player == null) { s.State = F.DontKnowWhere; s.RemainingTime = 0; break; } if (s.RemainingTime > 0) s.RemainingTime -= time.thisTickTimes; var vect = new Vector2(player.X - host.X, player.Y - host.Y); if (vect.Length > 20) { host.Move(player.X, player.Y); host.UpdateCount++; } else if (vect.Length > 1) { var dist = host.GetSpeed(0.5f) * (time.thisTickTimes / 1000f); if (vect.Length > 2) dist = host.GetSpeed(0.5f + ((float)player.Stats[4] / 100)) * (time.thisTickTimes / 1000f); else if (vect.Length > 3.5) dist = host.GetSpeed(0.5f + (player.Stats[4] + (float)player.Boost[4] / 100)) * (time.thisTickTimes / 1000f); else if (vect.Length > 5) dist = host.GetSpeed(1.0f + (player.Stats[4] + (float)player.Boost[4] / 100)) * (time.thisTickTimes / 1000f); else if (vect.Length > 6) dist = host.GetSpeed(1.35f + (player.Stats[4] + (float)player.Boost[4] / 100)) * (time.thisTickTimes / 1000f); else if (vect.Length > 7) dist = host.GetSpeed(1.5f + (player.Stats[4] + (float)player.Boost[4] / 100)) * (time.thisTickTimes / 1000f); else if (vect.Length > 10) dist = host.GetSpeed(2f + (player.Stats[4] + (float)player.Boost[4] / 100)) * (time.thisTickTimes / 1000f); Status = CycleStatus.InProgress; vect.Normalize(); host.ValidateAndMove(host.X + vect.X * dist, host.Y + vect.Y * dist); host.UpdateCount++; } break; } state = s; }
public static bool GenRandomRoom(World world, float x, float y, Wall theWall) { try { Random rand = new Random(); if (rand.Next(1, 60) != 1) { return(false); } //Console.Out.WriteLine("Generating room..."); List <string> dirs = new List <string>(); for (int tx = -1; tx <= 1; tx++) { for (int ty = -1; ty <= 1; ty++) { WmapTile targetTile = world.Map[(int)x + tx, (int)y + ty]; WmapTile thisTile = world.Map[(int)x, (int)y]; if (targetTile.TileId == 0xff) { if (tx == -1 && ty == 0) { dirs.Add("left"); } else if (tx == 1 && ty == 0) { dirs.Add("right"); } else if (tx == 0 && ty == 1) { dirs.Add("down"); } else if (tx == 0 && ty == -1) { dirs.Add("up"); } } } } if (dirs.Count < 1) { return(false); } dirs.Shuffle(); //Console.Out.WriteLine("Room direction: " + dirs.First()); float mainX = x; float mainY = y; float entranceX = x; float entranceY = y; switch (dirs.First()) { case "up": mainX = x - 6; mainY = y - 8; entranceY = y - 1; break; case "down": mainX = x - 6; mainY = y + 1; entranceY = y + 1; break; case "left": mainX = x - 12; mainY = y - 3; entranceX = x - 1; break; case "right": mainX = x + 1; mainY = y - 3; entranceX = x + 1; break; } List <WmapTile> addedTiles = new List <WmapTile>(); for (int ty = (int)mainY; ty <= mainY + 7; ty++) { for (int tx = (int)mainX; tx <= mainX + 11; tx++) { WmapTile tTile = world.Map[tx, ty]; if (tTile.TileId != 0xff || tTile.ObjType != 0) { //Console.Out.WriteLine("Found collision while generating room!"); return(false); } tTile.TileId = world.Map[(int)x, (int)y].TileId; addedTiles.Add(tTile); } } //Console.Out.WriteLine("Generated tiles, placing..."); int tileNum = 0; for (int ty = (int)mainY; ty <= mainY + 7; ty++) { for (int tx = (int)mainX; tx <= mainX + 11; tx++) { WmapTile ctile = addedTiles[tileNum]; if ((tx == (int)mainX || tx == (int)mainX + 11 || ty == (int)mainY || ty == (int)mainY + 7) && !(tx == entranceX && ty == entranceY)) { //Console.Out.WriteLine("Placed wall"); Wall e = new Wall(theWall.ObjectType, XmlDatas.TypeToElement[theWall.ObjectType]); e.Move(tx, ty); world.EnterWorld(e); ctile.ObjType = theWall.ObjectType; } else { //Console.Out.WriteLine("Placed treasure"); if (rand.Next(1, 30) == 1) { Entity e = Entity.Resolve(XmlDatas.IdToType["Coral Gift"]); e.Move(tx + 0.5f, ty + 0.5f); world.EnterWorld(e); ctile.ObjType = XmlDatas.IdToType["Coral Gift"]; } } world.Map[tx, ty] = ctile; } } //Console.Out.WriteLine("Placed tiles!"); return(true); } catch (Exception e) { return(false); } }
public static bool GenRandomRoom(World world, float x, float y, Wall theWall) { try { Random rand = new Random(); if (rand.Next(1, 60) != 1) { return(false); } //Console.Out.WriteLine("Generating room..."); List <string> dirs = new List <string>(); for (int tx = -1; tx <= 1; tx++) { for (int ty = -1; ty <= 1; ty++) { WmapTile targetTile = world.Map[(int)x + tx, (int)y + ty]; WmapTile thisTile = world.Map[(int)x, (int)y]; if (targetTile.TileId == 0xff) { if (tx == -1 && ty == 0) { dirs.Add("left"); } else if (tx == 1 && ty == 0) { dirs.Add("right"); } else if (tx == 0 && ty == 1) { dirs.Add("down"); } else if (tx == 0 && ty == -1) { dirs.Add("up"); } } } } if (dirs.Count < 1) { return(false); } dirs.Shuffle(); //Console.Out.WriteLine("Room direction: " + dirs.First()); float mainX = x; float mainY = y; float entranceX = x; float entranceY = y; int rsX = 1; int rsY = 1; do { rsX = rand.Next(6, 12 + 1); }while (rsX % 2 > 0); do { rsY = rand.Next(6, 12 + 1); }while (rsY % 2 > 0); //Console.Out.WriteLine("Room size: " + rsX + ", " + rsY); switch (dirs.First()) { case "up": mainX = x - (rsX / 2); mainY = y - rsY; entranceY = y - 1; break; case "down": mainX = x - (rsX / 2); mainY = y + 1; entranceY = y + 1; break; case "left": mainX = x - rsX; mainY = y - ((rsY - 2) / 2); entranceX = x - 1; break; case "right": mainX = x + 1; mainY = y - ((rsY - 2) / 2); entranceX = x + 1; break; } entranceX -= 0.5f; entranceY -= 0.5f; List <WmapTile> addedTiles = new List <WmapTile>(); for (int ty = (int)mainY; ty <= mainY + (rsY - 1); ty++) { for (int tx = (int)mainX; tx <= mainX + (rsX - 1); tx++) { WmapTile tTile = world.Map[tx, ty]; if (tTile.TileId != 0xff || tTile.ObjType != 0) { Console.Out.WriteLine("Found collision while generating room!"); return(false); } tTile.TileId = world.Map[(int)x, (int)y].TileId; addedTiles.Add(tTile); } } //Console.Out.WriteLine("Generated tiles, placing..."); int tileNum = 0; float blackPotSpotX = (float)rand.Next((int)mainX + 1, (int)mainX + rsX); float blackPotSpotY = (float)rand.Next((int)mainY + 1, (int)mainY + rsY); for (int ty = (int)mainY; ty <= mainY + (rsY - 1); ty++) { for (int tx = (int)mainX; tx <= mainX + (rsX - 1); tx++) { WmapTile ctile = addedTiles[tileNum]; world.Map[tx, ty] = ctile; if ((tx == (int)mainX || tx == (int)mainX + (rsX - 1) || ty == (int)mainY || ty == (int)mainY + (rsY - 1)) && !(tx == entranceX && ty == entranceY)) { //Console.Out.WriteLine(tx + ", " + ty + " - " + entranceX + ", " + entranceY); //Console.Out.WriteLine("Placed wall"); GenWall(world, tx + 0.5f, ty + 0.5f, rand); } else { //Console.Out.WriteLine("Placed treasure"); if (rand.Next(1, 25) == 1) { if ((world as Mine).RoomsFound == 3 ? (tx != blackPotSpotX && ty != blackPotSpotY) : true) { Entity e = Entity.Resolve((short)rand.Next(0x196f, 0x1972)); e.Move(tx + 0.5f, ty + 0.5f); world.EnterWorld(e); } } } } } (world as Mine).RoomsFound++; if ((world as Mine).RoomsFound == 4) { Entity e = Entity.Resolve(XmlDatas.IdToType["Pot of Descent"]); e.Move(blackPotSpotX + 0.5f, blackPotSpotY + 0.5f); world.EnterWorld(e); } //Console.Out.WriteLine("Placed tiles!"); return(true); } catch (Exception e) { return(false); } }
public virtual void SpawnEntity(Entity entity) { IntPoint tile = GetRandomTile(TileRegion.Spawn); entity.Move(tile.X + 0.5f, tile.Y + 0.5f); }
public virtual void SpawnEntity(Entity entity) { IntPoint tile = GetRandomTile(TileRegion.Spawn); entity.Move(tile.X + 0.5f, tile.Y + 0.5f); }
protected override void OnStateEntry(Entity host, RealmTime time, ref object state) { host.Move(host.X + Random.Next(minX, maxX), host.Y + Random.Next(minY, maxY)); host.UpdateCount++; }
public virtual void RemoveEntity(Entity entity) { entity.Move(-1, -1); }