public override void Update(TimeSpan elapsed) { foreach (var pokemon in World.Instance.Population) { if (!pokemon.IsVisible && RandomUtils.RandomDouble() < SPAWN_RATE) { World.Instance.VisibleEntities.Add(pokemon, pokemon.HiddenPosition); } else if (pokemon.IsVisible && GlobalServer.Instance.GetBattle(pokemon.Id) == null && RandomUtils.RandomDouble() < HIDE_RATE) { World.Instance.VisibleEntities.Remove(pokemon.Id); } else if (pokemon.IsVisible && GlobalServer.Instance.GetBattle(pokemon.Id) == null && RandomUtils.RandomDouble() < MOVE_RATE) { var dest = new Position(pokemon.Position, DirectionUtils.RandomDirection()); EntityState newState; if (World.Instance.Map.CanGo(pokemon, dest, out newState)) { World.Instance.VisibleEntities.Move(pokemon.Id, dest); pokemon.State = newState; } } } base.Update(elapsed); }
public BattleActionParam(Direction dir, Position target, Action action) : this() { this.Direction = dir; this.Target = target; this.Action = action; }
public BattleTrainerActionParam(Position target, Action action, int index) : this() { this.Index = index; this.Target = target; this.Action = action; }
public BattleActionMessage(string battleStr) { var actionId = battleStr.Split('=')[0]; ActionId = System.Int32.Parse(actionId); ActionsAvailable = new List<TrainerAction>(); var actionAvailStr = battleStr.Split('=')[1]; for (int i = 0; i < actionAvailStr.Split(',').Count(); i++) { ActionsAvailable.Add((TrainerAction)(System.Int32.Parse(actionAvailStr.Split(',')[i]))); } var actionStr = battleStr.Split('=')[2]; if (actionStr != "0") { Target = new Position(actionStr.Split(',')[0]); Action = Moves.Get((Move)(System.Int32.Parse(actionStr.Split(',')[1]))); Dir = DirectionUtils.FromString(actionStr.Split(',')[2]); } var stateStr = battleStr.Split('=')[3]; if (stateStr != "0") { State = new BattleStateMessage(stateStr); } }
public List<Position> InRangeTiles(BattleEntity self, Direction dir, BattleArena arena) { var result = new List<Position>(); for (int x = 0; x < arena.ArenaSize; x++) { for (int y = 0; y < arena.ArenaSize; y++) { Position target = new Position(x, y); if (dir == Direction.None) { if (InRange(arena, self, target)) { result.Add(target); } } else { if (InRange(arena, self, target, dir)) { result.Add(target); } } } } return result; }
private MapMessage GetMapUpdate(Player player) { Position segment = player.Position.GetSegment(Settings.Default.ChunkSize); var startx = (segment.X - 1) * 20; var starty = (segment.Y - 1) * 20; if (startx < 0) startx = 0; if (starty < 0) starty = 0; Position startPos = new Position(startx, starty); string message = String.Empty; var endx = (segment.X + 2) * 20; var endy = (segment.Y + 2) * 20; for (int y = starty; y < endy - 1; y++) { for (int x = startx; x < endx - 1; x++) { Position pos = new Position(x, y); message += (int)World.Instance.Map.GetTile(pos); message += "."; message += (int)World.Instance.Map.GetObject(pos); message += ","; } } message = message.Remove(message.Length - 1, 1); return new MapMessage(startPos, message); }
public override bool InArea(Position origin, Position target, Direction dir) { var dist = Math.Abs(origin.X - target.X) + Math.Abs(origin.Y - target.Y); if (dist <= Dist) { return true; } return false; }
public PositionEntity(int id, Position position, EntityType type, Direction orientation, int pokedexId, EntityState state) { Id = id; Position = position; Type = type; Orientation = orientation; PokedexId = pokedexId; State = state; }
public override void ApplyCost(BattleEntity self, Position target) { int cost = Position.Distance(self.CurrentPos, target) * Value; self.MP -= cost; if (self.MP < 0) { self.AP += self.MP; self.MP = 0; } }
public override bool InRange(BattleArena arena, BattleEntity self, Position target, Direction dir) { var origin = self.CurrentPos; var dist = Math.Abs(origin.X - target.X) + Math.Abs(origin.Y - target.Y); if (dist <= Dist && dist != 0) { return true; } return false; }
public override bool InRange(BattleArena arena, BattleEntity self, Position target) { foreach (Direction dir in Enum.GetValues(typeof(Direction))) { if (InRange(arena, self, target, dir)) { return true; } } return false; }
public Position(Position pos, Direction dir) { X = pos.X; Y = pos.Y; switch (dir) { case Direction.Down: Y++; break; case Direction.Right: X++; break; case Direction.Up: Y--; break; case Direction.Left: X--; break; } }
public BattleStateEntity(string entityStr) { Id = Int32.Parse(entityStr.Split(',')[0]); PokemonId = Int32.Parse(entityStr.Split(',')[1]); PlayerId = Int32.Parse(entityStr.Split(',')[2]); CurrentPos = new Position(entityStr.Split(',')[3]); ComingBack = "1" == entityStr.Split(',')[4]; HP = Int32.Parse(entityStr.Split(',')[5]); MaxHP = Int32.Parse(entityStr.Split(',')[6]); AP = Int32.Parse(entityStr.Split(',')[7]); MaxAP = Int32.Parse(entityStr.Split(',')[8]); MP = Int32.Parse(entityStr.Split(',')[9]); MaxMP = Int32.Parse(entityStr.Split(',')[10]); }
public Pokemon(int pokemonId, Position hiddenPosition) : base(EntityType.Pokemon, pokemonId == 3, true, pokemonId == 2) { PokedexId = pokemonId; Level = 1; Xp = 0; Age = 1; Sex = RandomUtils.CoinToss() ? Gender.Female : Gender.Male; NoRepTime = 0; HiddenPosition = hiddenPosition; }
public override bool InArea(Position origin, Position target, Direction dir) { switch (dir) { case Direction.Up: return target.X == origin.X && target.Y >= origin.Y && target.Y - Dist < origin.Y; case Direction.Right: return target.Y == origin.Y && target.X >= origin.X && target.X - Dist < origin.X; case Direction.Down: return target.X == origin.X && target.Y <= origin.Y && target.Y + Dist > origin.Y; case Direction.Left: return target.Y == origin.Y && target.X <= origin.X && target.X + Dist > origin.X; default: return false; } }
public override void DeserializeArguments(string args) { try { var splitArgs = args.Split('+'); Origin = new Position(splitArgs[0]); Segments = splitArgs[1]; IsValid = true; } catch (Exception) { IsValid = false; } }
public override bool InRange(BattleArena arena, BattleEntity self, Position target, Direction dir) { var origin = self.CurrentPos; switch (dir) { case Direction.Up: return target.X == origin.X && target.Y > origin.Y && target.Y - Dist <= origin.Y; case Direction.Right: return target.Y == origin.Y && target.X > origin.X && target.X - Dist <= origin.X; case Direction.Down: return target.X == origin.X && target.Y < origin.Y && target.Y + Dist >= origin.Y; case Direction.Left: return target.Y == origin.Y && target.X < origin.X && target.X + Dist >= origin.X; default: return false; } }
public PositionEntity(string args) { var argsSplit = args.Split('='); var entityInfos = argsSplit[0].Split('-'); var entityValues = argsSplit[1].Split(':'); var id = entityInfos[1]; var type = entityInfos[0]; var pokedexId = entityInfos[2]; var position = String.Format("{0}:{1}", entityValues[0], entityValues[1]); var dir = entityValues[2]; var state = entityValues[3]; Id = Int32.Parse(id); Position = new Position(position); Type = EntityTypeUtils.FromString(type); Orientation = DirectionUtils.FromString(dir); PokedexId = Int32.Parse(pokedexId); State = StateUtils.FromString(state); }
public override void DeserializeArguments(string args) { var splitedArg = args.Split(','); if (splitedArg.Length < 3) { this.IsValid = false; } else { try { Target = new Position(splitedArg[0]); Action = Moves.Get((Move)Int32.Parse(splitedArg[1])); Direction = DirectionUtils.FromString(splitedArg[2]); this.IsValid = true; } catch (Exception) { this.IsValid = false; } } }
public override void DeserializeArguments(string args) { var splitedArgs = args.Split(','); if (splitedArgs.Length < 3) { IsValid = false; } else { try { Target = new Position(splitedArgs[0]); Action = TrainerActions.Get((TrainerAction)Int32.Parse(splitedArgs[1])); Index = Int32.Parse(splitedArgs[2]); IsValid = true; } catch (Exception) { IsValid = false; } } }
public abstract bool InRange(BattleArena arena, BattleEntity self, Position target, Direction dir);
public List<Position> AoeTiles(BattleEntity self, Position target, Direction dir, BattleArena arena) { var result = new List<Position>(); if (AreaOfEffect == null) { result.Add(target); return result; } int startX = Position.NormalizedPos(target.X - AreaOfEffect.MaxArea, arena.ArenaSize); int endX = Position.NormalizedPos(target.X + AreaOfEffect.MaxArea, arena.ArenaSize); int startY = Position.NormalizedPos(target.Y - AreaOfEffect.MaxArea, arena.ArenaSize); int endY = Position.NormalizedPos(target.Y + AreaOfEffect.MaxArea, arena.ArenaSize); for (int x = startX; x <= endX; x++) { for (int y = startY; y <= endY; y++) { Position origin = target; Position aoe = new Position(x, y); bool inArea = false; if (TargetType == TargetType.Position) { if (AreaOfEffect.InArea(origin, aoe)) { inArea = true; } } if (TargetType == TargetType.Directional) { if (AreaOfEffect.InArea(origin, aoe, dir)) { inArea = true; } } if (inArea) { result.Add(aoe); } } } return result; }
public override void ApplyCost(BattleEntity self, Position target) { self.MP -= Value; }
public static int Distance(Position p1, Position p2) { return Math.Abs(p1.X - p2.X) + Math.Abs(p1.Y - p2.Y); }
public override void apply(BattleEntity self, BattleEntity target, Direction dir, BattleArena arena) { Position newPos = new Position(target.CurrentPos.X + PositionUtils.GetDirPosition(dir).X * Dist, target.CurrentPos.Y + PositionUtils.GetDirPosition(dir).Y * Dist); newPos.NormalizePos(arena.ArenaSize); arena.MoveBattleEntity(target, newPos); }
public Position(Position pos) { X = pos.X; Y = pos.Y; }
public MapMessage(Position origin, string segments) : this() { Origin = origin; Segments = segments; }
public virtual bool InRange(BattleArena arena, BattleEntity self, Position target) { return InRange(arena, self, target, Direction.None); }
public void apply(BattleEntity self, Position target, BattleArena arena) { apply(self, target, Direction.None, arena); }
public abstract void apply(BattleEntity self, Position target, Direction dir, BattleArena arena);