Example #1
0
        public BattleResultViewModel Attack([FromQuery] string enemyPlayerId)
        {
            var result = unitRepositoryWrite.Attack(currentUserContext.PlayerId, PlayerIdFactory.Create(enemyPlayerId));

            return(new BattleResultViewModel {
            });
        }
 private static DictionaryJsonConverterFactory GetIdConverters()
 {
     return(new DictionaryJsonConverterFactoryBuilder()
            .AddParser <PlayerId>((str) => PlayerIdFactory.Create(str))
            .AddParser <AssetDefId>((str) => Id.AssetDef(str))
            .AddParser <UnitDefId>((str) => Id.UnitDef(str))
            .AddParser <ResourceDefId>((str) => Id.ResDef(str))
            .AddParser <PlayerTypeDefId>((str) => Id.PlayerType(str))
            .AddParser <UnitId>((str) => Id.UnitId(Guid.Parse(str)))
            .Build());
 }
Example #3
0
 public async Task <IActionResult> SignInDev([FromForm] string playerid)
 {
     // only works if DevAuth setting in appsettings is set (dev only!)
     if (!options.Value.DevAuth)
     {
         return(BadRequest());
     }
     if (string.IsNullOrWhiteSpace(playerid))
     {
         return(BadRequest());
     }
     return(CreatePlayer(PlayerIdFactory.Create(playerid)));
 }
        private static WorldStateImmutable CreateWorldState(string playerType = "type1", string assetDefId = "asset1", string unitDefId = "unit1", string resDefId = "res1")
        {
            var players  = new List <PlayerImmutable>();
            var gameTick = new GameTick(0);

            players.Add(
                new PlayerImmutable(
                    PlayerId: PlayerIdFactory.Create("player1"),
                    PlayerType: Id.PlayerType(playerType),
                    Name: "player1",
                    Created: DateTime.Now,
                    State: new PlayerStateImmutable(
                        LastGameTickUpdate: DateTime.Now,
                        CurrentGameTick: gameTick,
                        Resources: new Dictionary <ResourceDefId, decimal> {
                { Id.ResDef(resDefId), 50 }
            },
                        Assets: new HashSet <AssetImmutable> {
                new AssetImmutable(
                    AssetDefId: Id.AssetDef(assetDefId),
                    Level: 1
                    )
            },
                        Units: new List <UnitImmutable> {
                new UnitImmutable(
                    UnitId: Id.NewUnitId(),
                    UnitDefId: Id.UnitDef(unitDefId),
                    Count: 10,
                    Position: null
                    )
            }
                        )
                    )
                );
            return(new WorldStateImmutable(
                       players.ToDictionary(x => x.PlayerId),
                       new GameTickStateImmutable(gameTick, DateTime.Now),
                       new List <GameActionImmutable>()
                       ));
        }
Example #5
0
 public static CurrentUserContext Create(string playerId)
 {
     return(new CurrentUserContext {
         PlayerId = PlayerIdFactory.Create(playerId)
     });
 }
Example #6
0
 public ActionResult <EnemyBaseViewModel> EnemyBase([FromQuery] string enemyPlayerId)
 {
     try {
         return(new EnemyBaseViewModel {
             PlayerAttackingUnits = new UnitsViewModel {
                 Units = unitRepository.GetAttackingUnits(currentUserContext.PlayerId, PlayerIdFactory.Create(enemyPlayerId))
                         .Select(x => x.ToUnitViewModel(unitRepository, currentUserContext, gameDef)).ToList()
             },
             EnemyDefendingUnits = new UnitsViewModel {
                 Units = unitRepository.GetDefendingEnemyUnits(currentUserContext.PlayerId, PlayerIdFactory.Create(enemyPlayerId))
                         .Select(x => x.ToUnitViewModel(unitRepository, currentUserContext, gameDef)).ToList()
             }
         });
     } catch (CannotViewEnemyBaseException e) {
         return(BadRequest(e.Message));
     }
 }
Example #7
0
 public async Task <ActionResult> SendUnits([FromQuery] string unitId, [FromQuery] string enemyPlayerId)
 {
     try {
         unitRepositoryWrite.SendUnit(new SendUnitCommand(currentUserContext.PlayerId, Id.UnitId(unitId), PlayerIdFactory.Create(enemyPlayerId)));
         return(Ok());
     } catch (Exception e) {
         return(BadRequest(e.Message));
     }
 }
Example #8
0
        public WorldStateImmutable CreateDevWorldState()
        {
            var players = new List <PlayerImmutable>();

            var gameTick = new GameTick(0);

            int playerCount = 5;

            for (int i = 0; i < playerCount; i++)
            {
                players.Add(
                    new PlayerImmutable(
                        PlayerId: PlayerIdFactory.Create($"discostu#{i}"),
                        PlayerType: Id.PlayerType("terran"),
                        Name: $"Commander Discostu#{i}",
                        Created: DateTime.Now,
                        State: new PlayerStateImmutable(
                            LastGameTickUpdate: DateTime.Now,
                            CurrentGameTick: gameTick,
                            Resources: new Dictionary <ResourceDefId, decimal> {
                    { Id.ResDef("land"), 50 },
                    { Id.ResDef("minerals"), 5000 },
                    { Id.ResDef("gas"), 3000 }
                },
                            Assets: new HashSet <AssetImmutable> {
                    new AssetImmutable(
                        AssetDefId: Id.AssetDef("commandcenter"),
                        Level: 1
                        ),
                    new AssetImmutable(
                        AssetDefId: Id.AssetDef("factory"),
                        Level: 1
                        ),
                    new AssetImmutable(
                        AssetDefId: Id.AssetDef("armory"),
                        Level: 1
                        ),
                    new AssetImmutable(
                        AssetDefId: Id.AssetDef("spaceport"),
                        Level: 1
                        )
                },
                            Units: new List <UnitImmutable> {
                    new UnitImmutable(
                        UnitId: Id.NewUnitId(),
                        UnitDefId: Id.UnitDef("wbf"),
                        Count: 10,
                        Position: null
                        ),
                    new UnitImmutable(
                        UnitId: Id.NewUnitId(),
                        UnitDefId: Id.UnitDef("spacemarine"),
                        Count: 25,
                        Position: null
                        ),
                    new UnitImmutable(
                        UnitId: Id.NewUnitId(),
                        UnitDefId: Id.UnitDef("siegetank"),
                        Count: 3,
                        Position: i == 0 ? null : PlayerIdFactory.Create("discostu#0")
                        ),
                }
                            )
                        )
                    );
            }

            return(new WorldStateImmutable(
                       players.ToDictionary(x => x.PlayerId),
                       new GameTickStateImmutable(gameTick, DateTime.Now - TimeSpan.FromMinutes(1)),
                       new List <GameActionImmutable>()
                       ));
        }
Example #9
0
 public override PlayerId Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
 {
     return(PlayerIdFactory.Create(reader.GetString()));
 }