コード例 #1
0
        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);
        }
コード例 #2
0
 public BattleActionParam(Direction dir, Position target, Action action)
     : this()
 {
     this.Direction = dir;
     this.Target = target;
     this.Action = action;
 }
コード例 #3
0
 public BattleTrainerActionParam(Position target, Action action, int index)
     : this()
 {
     this.Index = index;
     this.Target = target;
     this.Action = action;
 }
コード例 #4
0
        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);
            }
        }
コード例 #5
0
        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;
        }
コード例 #6
0
        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);
        }
コード例 #7
0
 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;
 }
コード例 #8
0
 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;
 }
コード例 #9
0
 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;
     }
 }
コード例 #10
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;
 }
コード例 #11
0
 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;
 }
コード例 #12
0
        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;
            }
        }
コード例 #13
0
 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]);
 }
コード例 #14
0
        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;
        }
コード例 #15
0
 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;
     }
 }
コード例 #16
0
        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;
            }
        }
コード例 #17
0
 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;
     }
 }
コード例 #18
0
        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);
        }
コード例 #19
0
        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;
                }
            }
        }
コード例 #20
0
        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;
                }
            }
        }
コード例 #21
0
 public abstract bool InRange(BattleArena arena, BattleEntity self, Position target, Direction dir);
コード例 #22
0
        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;
        }
コード例 #23
0
 public override void ApplyCost(BattleEntity self, Position target)
 {
     self.MP -= Value;
 }
コード例 #24
0
 public static int Distance(Position p1, Position p2)
 {
     return Math.Abs(p1.X - p2.X) + Math.Abs(p1.Y - p2.Y);
 }
コード例 #25
0
 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);
 }
コード例 #26
0
 public Position(Position pos)
 {
     X = pos.X;
     Y = pos.Y;
 }
コード例 #27
0
 public MapMessage(Position origin, string segments)
     : this()
 {
     Origin = origin;
     Segments = segments;
 }
コード例 #28
0
 public virtual bool InRange(BattleArena arena, BattleEntity self, Position target)
 {
     return InRange(arena, self, target, Direction.None);
 }
コード例 #29
0
 public void apply(BattleEntity self, Position target, BattleArena arena)
 {
     apply(self, target, Direction.None, arena);
 }
コード例 #30
0
 public abstract void apply(BattleEntity self, Position target, Direction dir, BattleArena arena);