コード例 #1
0
ファイル: ShipCreationLogsVM.cs プロジェクト: lyu0912/ing
 public ShipCreationLogsVM(Logger logger, NavalBase navalBase, ILocalizationService localization)
 {
     this.logger       = logger;
     this.localization = localization;
     masterData        = navalBase.MasterData;
     nsc = localization.GetLocalized("GameModel", "ConstructionType_Normal");
     lsc = localization.GetLocalized("GameModel", "ConstructionType_Large");
 }
コード例 #2
0
 public EquipmentCreationLogsVM(Logger logger, NavalBase navalBase, ILocalizationService localization)
 {
     this.logger       = logger;
     this.localization = localization;
     masterData        = navalBase.MasterData;
     success           = localization.GetLocalized("GameModel", "Success");
     fail = localization.GetLocalized("GameModel", "Fail");
 }
コード例 #3
0
        public static void TestHomeportParse()
        {
            var provider     = new UnitTestProvider();
            var gameListener = new GameListener(new UnitTestProviderSelector(provider));
            var navalBase    = new NavalBase(gameListener, null, null);

            using (var stream = Assembly.GetExecutingAssembly()
                                .GetManifestResourceStream(typeof(MasterDataTest), "Data.port.2018-05-28_015208.676_START2.json"))
                provider.Push("api_start2", DateTimeOffset.Now, default, stream);
コード例 #4
0
ファイル: EquipmentCatalogVM.cs プロジェクト: lyu0912/ing
 public EquipmentCatalogVM(NavalBase navalBase)
 {
     source          = navalBase.AllEquipment;
     source.Updated += new LifeTimeTracker(source, this).Update;
     IconFilters     = navalBase.MasterData.EquipmentInfos
                       .Select(x => x.IconId)
                       .Distinct().OrderBy(x => x)
                       .Select(x => new EquipmentIconHolder(this, x))
                       .ToArray();
     Update();
 }
コード例 #5
0
ファイル: HomeportTest.cs プロジェクト: CodeForCSharp/ing
        public void TestHomeportParse()
        {
            var provider     = new UnitTestProvider();
            var gameListener = new GameListener(provider);
            var navalBase    = new NavalBase(gameListener, null);

            using (var stream = Assembly.GetExecutingAssembly()
                                .GetManifestResourceStream(typeof(MasterDataTest), "Data.port.2018-05-28_015208.676_START2.json"))
                provider.Push("api_start2", DateTimeOffset.Now, string.Empty, stream);
            using (var stream = Assembly.GetExecutingAssembly()
                                .GetManifestResourceStream(typeof(MasterDataTest), "Data.port.2018-05-28_015210.298_REQUIRE_INFO.json"))
                provider.Push("api_get_member/require_info", DateTimeOffset.Now, string.Empty, stream);
            using (var stream = Assembly.GetExecutingAssembly()
                                .GetManifestResourceStream(typeof(MasterDataTest), "Data.port.2018-05-28_015212.349_PORT.json"))
                provider.Push("api_port/port", DateTimeOffset.Now, string.Empty, stream);
        }
コード例 #6
0
 public MapRouting(NavalBase navalBase, RawMapRouting m)
 {
     Map       = navalBase.Maps[m.MapId];
     RouteId   = m.RouteId;
     EventKind = m.EventKind;
     if (EventKind == MapEventKind.Battle || EventKind == MapEventKind.Boss)
     {
         BattleKind = m.BattleKind;
     }
     CanMoveAdvance       = m.CanMoveAdvance;
     Reconnaissance       = m.Reconnaissance;
     Message              = m.Message;
     SelectableRoutes     = m.SelectableRoutes;
     RankingPointAcquired = m.RankingPointAcquired;
     UseItemChanges       = m.ItemAcquired.Select(x => new UseItemChange(navalBase.MasterData.UseItems[x.ItemId], x.Count))
                            .Concat(m.ItemLost.Select(x => new UseItemChange(navalBase.MasterData.UseItems[x.ItemId], -x.Count)))
                            .ToArray();
     if (m.LandBaseDefence != null)
     {
         LandBaseDefence = new LandBaseDefenceBattle(navalBase.MasterData, m.LandBaseDefence);
     }
 }
コード例 #7
0
 public AirForceSquadron(IRawAirForceSquadron raw, NavalBase owner, DateTimeOffset timeStamp) : this(raw.Id, owner) => UpdateProps(raw, timeStamp);
コード例 #8
0
 public AirForceSquadron(int id, NavalBase owner) : base(id)
 {
     this.owner = owner;
     CreateDummy();
 }
コード例 #9
0
 public Map(IRawMap raw, NavalBase owner, DateTimeOffset timeStamp) : this(raw.Id, owner) => UpdateProps(raw, timeStamp);
コード例 #10
0
 public Map(MapId id, NavalBase owner) : base(id)
 {
     this.owner = owner;
     CreateDummy();
 }
コード例 #11
0
ファイル: FleetsView.xaml.cs プロジェクト: lyu0912/ing
 public FleetsView(NavalBase viewModel)
 {
     ViewModel = viewModel;
     InitializeComponent();
 }
コード例 #12
0
ファイル: Logger.cs プロジェクト: lyu0912/ing
        public Logger(IDataService dataService, GameProvider provider, NavalBase navalBase, IStatePersist statePersist)
        {
            this.dataService  = dataService;
            this.navalBase    = navalBase;
            this.statePersist = statePersist;

            provider.EquipmentCreated += (t, m) =>
            {
                using var context = CreateContext();
                context.EquipmentCreationTable.AddRange(m.Equipment.Select((e, i) => new EquipmentCreationEntity
                {
                    TimeStamp        = t.AddMilliseconds(i),
                    Consumption      = m.Consumption,
                    EquipmentCreated = e?.EquipmentInfoId,
                    IsSuccess        = e is object,
                    AdmiralLevel     = this.navalBase.Admiral.Leveling.Level,
                    Secretary        = this.navalBase.Secretary.Info.Id,
                    SecretaryLevel   = this.navalBase.Secretary.Leveling.Level
                }));
                context.SaveChanges();
            };

            provider.ShipCreated += (t, m) =>
            {
                shipCreation = new ShipCreationEntity
                {
                    TimeStamp      = t,
                    Consumption    = m.Consumption,
                    IsLSC          = m.IsLSC,
                    AdmiralLevel   = this.navalBase.Admiral.Leveling.Level,
                    Secretary      = this.navalBase.Secretary.Info.Id,
                    SecretaryLevel = this.navalBase.Secretary.Leveling.Level
                };
                lastBuildingDock = m.BuildingDockId;
            };

            provider.BuildingDockUpdated += (t, m) =>
            {
                if (shipCreation != null)
                {
                    using var context           = CreateContext();
                    shipCreation.ShipBuilt      = m.Single(x => x.Id == lastBuildingDock).BuiltShipId.Value;
                    shipCreation.EmptyDockCount = this.navalBase.BuildingDocks.Count(x => x.State == BuildingDockState.Empty);
                    context.ShipCreationTable.Add(shipCreation);
                    shipCreation     = null;
                    lastBuildingDock = default;
                    context.SaveChanges();
                }
            };

            provider.ExpeditionCompleted += (t, m) =>
            {
                using var context = CreateContext();
                var fleet = this.navalBase.Fleets[m.FleetId];
                context.ExpeditionCompletionTable.Add(new ExpeditionCompletionEntity
                {
                    TimeStamp         = t,
                    ExpeditionId      = fleet.Expedition.Id,
                    ExpeditionName    = m.ExpeditionName,
                    Result            = m.Result,
                    MaterialsAcquired = m.MaterialsAcquired,
                    RewardItem1       = m.RewardItem1,
                    RewardItem2       = m.RewardItem2
                });
                context.SaveChanges();
                foreach (var ship in fleet.HomeportShips)
                {
                    this.statePersist.ClearLastSortie(ship.Id);
                }
                this.statePersist.SaveChanges();
            };

#if DEBUG
            InitializeAdmiral(null);
#endif

            navalBase.AdmiralChanging += (t, _, a) =>
            {
                if (a != null)
                {
                    lock (admiralLock)
                        InitializeAdmiral(a);
                }
            };

            navalBase.MaterialsUpdating += (t, old, @new, reason) =>
            {
                using var context = CreateContext();
                context.MaterialsChangeTable.Add(new MaterialsChangeEntity
                {
                    TimeStamp = t,
                    Materials = @new,
                    Reason    = reason
                });
                context.SaveChanges();
            };

            navalBase.HomeportUpdated += (t, n) =>
            {
                if (this.statePersist.LastSortieTime is DateTimeOffset last)
                {
                    currentBattleContext ??= CreateContext();

                    var consumption = this.navalBase.Fleets[this.statePersist.LastSortieFleets].Sum(f => f.RepairingCost + f.SupplyingCost);
                    var diff        = consumption - this.statePersist.ConsumptionBeforeSortie;
                    var entity      = currentBattleContext.BattleConsumptionTable.Find(last);
                    if (diff != default && entity != null)
                    {
                        entity.Consumption = diff;
                        currentBattleContext.BattleConsumptionTable.Update(entity);
                        currentBattleContext.SaveChanges();
                    }
                }

                currentBattle   = null;
                currentExercise = null;
                currentBattleContext?.Dispose();
                currentFleetInBattle  = null;
                currentFleet2InBattle = null;

                this.statePersist.LastSortieFleets = null;
                this.statePersist.LastSortieTime   = null;
                this.statePersist.SaveChanges();
            };

            navalBase.ShipSupplying += (t, s, raw) =>
            {
                if (this.statePersist.GetLastSortie(s.Id) is DateTimeOffset last)
                {
                    using var context = CreateContext();
                    var entity = context.BattleConsumptionTable.Find(last);
                    if (entity is null)
                    {
                        return;
                    }

                    int  fuel        = raw.CurrentFuel - s.Fuel.Current;
                    int  bullet      = raw.CurrentBullet - s.Bullet.Current;
                    bool isMarriaged = s.Leveling.Level >= 100;
                    entity.ActualConsumption += new Materials
                    {
                        Fuel    = isMarriaged ? (int)(fuel * 0.85) : fuel,
                        Bullet  = isMarriaged ? (int)(bullet * 0.85) : bullet,
                        Bauxite = (raw.SlotAircraft.Sum() - s.Slots.Sum(x => x.Aircraft.Current)) * 5
                    };
                    context.BattleConsumptionTable.Update(entity);
                    context.SaveChanges();
                }
            };

            navalBase.ShipRepairing += (t, s, i) =>
            {
                if (this.statePersist.GetLastSortie(s.Id) is DateTimeOffset last)
                {
                    using var context = CreateContext();
                    var entity = context.BattleConsumptionTable.Find(last);
                    if (entity is null)
                    {
                        return;
                    }

                    entity.ActualConsumption += s.RepairingCost;
                    if (i)
                    {
                        entity.ActualConsumption += new Materials
                        {
                            InstantRepair = 1
                        }
                    }
                    ;
                    context.BattleConsumptionTable.Update(entity);
                    context.SaveChanges();
                }
            };
            navalBase.RepairingDockInstant += (t, d, s) =>
            {
                if (this.statePersist.GetLastSortie(s.Id) is DateTimeOffset last)
                {
                    using var context = CreateContext();
                    var entity = context.BattleConsumptionTable.Find(last);
                    if (entity is null)
                    {
                        return;
                    }


                    entity.ActualConsumption += new Materials
                    {
                        InstantRepair = 1
                    };
                    context.BattleConsumptionTable.Update(entity);
                    context.SaveChanges();
                }
            };

            provider.SortieStarting += (t, m) =>
            {
                FleetId[] fleets;
                currentFleetInBattle = this.navalBase.Fleets[m.FleetId];
                currentCombinedFleet = this.navalBase.CombinedFleet;
                if (currentCombinedFleet != CombinedFleetType.None)
                {
                    currentFleet2InBattle = this.navalBase.Fleets[(FleetId)2];
                    fleets = new[] { (FleetId)1, (FleetId)2 };
                }
                else
                {
                    fleets = new[] { m.FleetId };
                }
                currentBattleContext = CreateContext();
                currentBattleContext.BattleConsumptionTable.Add(new BattleConsumptionEntity
                {
                    TimeStamp = t,
                    MapId     = m.MapId
                });
                currentBattleContext.SaveChanges();

                this.statePersist.ConsumptionBeforeSortie =
                    currentFleetInBattle.RepairingCost +
                    currentFleetInBattle.SupplyingCost +
                    (currentFleet2InBattle?.RepairingCost ?? default) +
                    (currentFleet2InBattle?.SupplyingCost ?? default);
                this.statePersist.LastSortieTime   = t;
                this.statePersist.LastSortieFleets = fleets;
                foreach (var ship in currentFleetInBattle.HomeportShips)
                {
                    this.statePersist.SetLastSortie(ship.Id, t);
                }
                if (currentFleet2InBattle != null)
                {
                    foreach (var ship in currentFleet2InBattle.HomeportShips)
                    {
                        this.statePersist.SetLastSortie(ship.Id, t);
                    }
                }
                this.statePersist.SaveChanges();
            };

            provider.MapRouting += (t, m) =>
            {
                var map = this.navalBase.Maps[m.MapId];
                currentBattle = new BattleEntity
                {
                    TimeStamp         = t,
                    CompletionTime    = t,
                    MapId             = m.MapId,
                    MapName           = map.Info.Name.Origin,
                    RouteId           = m.RouteId,
                    EventKind         = m.EventKind,
                    BattleKind        = m.BattleKind,
                    CombinedFleetType = this.navalBase.CombinedFleet,
                    MapRank           = map.Rank,
                    MapGaugeType      = map.GaugeType,
                    MapGaugeNumber    = map.GaugeIndex,
                    MapGaugeHP        = map.Gauge?.Current,
                    MapGaugeMaxHP     = map.Gauge?.Max
                };
                if (m.UnparsedLandBaseDefence != null)
                {
                    currentBattle.LandBaseDefence = m.UnparsedLandBaseDefence.ToString(Formatting.None);
                }

                Materials acquired = default;
                foreach (var r in m.ItemAcquired)
                {
                    switch ((KnownUseItem)r.ItemId)
                    {
                    case KnownUseItem.Fuel:
                        acquired.Fuel += r.Count;
                        break;

                    case KnownUseItem.Bullet:
                        acquired.Bullet += r.Count;
                        break;

                    case KnownUseItem.Steel:
                        acquired.Steel += r.Count;
                        break;

                    case KnownUseItem.Bauxite:
                        acquired.Bauxite += r.Count;
                        break;

                    case KnownUseItem.InstantBuild:
                        acquired.InstantBuild += r.Count;
                        break;

                    case KnownUseItem.InstantRepair:
                        acquired.InstantRepair += r.Count;
                        break;

                    case KnownUseItem.Development:
                        acquired.Development += r.Count;
                        break;

                    case KnownUseItem.Improvement:
                        acquired.Improvement += r.Count;
                        break;
                    }
                }
                if (acquired != default)
                {
                    var entity = currentBattleContext.BattleConsumptionTable.Find(this.statePersist.LastSortieTime);
                    if (entity != null)
                    {
                        entity.Acquired += acquired;
                        currentBattleContext.BattleConsumptionTable.Update(entity);
                    }
                }

                currentBattleContext.BattleTable.Add(currentBattle);
                currentBattleContext.SaveChanges();
            };

            provider.ExerciseCandidateSelected += (t, m) =>
            {
                currentExercise = new ExerciseEntity
                {
                    TimeStamp  = t,
                    EnemyId    = m.AdmiralId,
                    EnemyName  = m.Name,
                    EnemyLevel = m.Leveling.Level
                };
            };

            provider.ExerciseStarted += (t, m) =>
            {
                currentFleetInBattle = this.navalBase.Fleets[m];
                currentBattleContext = CreateContext();
            };

            provider.BattleStarted += (t, m) =>
            {
                if (currentBattle != null)
                {
                    currentBattle.CompletionTime    = t;
                    currentBattle.SortieFleetState  = currentFleetInBattle.Ships.Select(x => new ShipInBattleEntity(x)).ToArray();
                    currentBattle.SortieFleet2State = currentFleet2InBattle?.Ships.Select(x => new ShipInBattleEntity(x)).ToArray();
                    currentBattle.FirstBattleDetail = m.Unparsed.ToString(Formatting.None);
                    currentBattle.LbasState         = m.Parsed.LandBasePhases
                                                      .Select(x => new AirForceInBattle(this.navalBase.AirForce[(currentBattle.MapId.AreaId, x.GroupId)]))
                                                      .ToArray();
                }
コード例 #13
0
ファイル: BattleManager.cs プロジェクト: IgNit3R/ing
        internal BattleManager(GameProvider listener, NavalBase navalBase)
        {
            this.navalBase = navalBase;

            listener.HomeportReturned += (t, m) =>
            {
                using (EnterBatchNotifyScope())
                {
                    CurrentRouting = null;
                    CurrentBattle  = null;
                    sortieFleet    = null;
                    sortieFleet2   = null;
                    exerciseFleet  = null;
                }
            };

            listener.ExerciseStarted += (t, m) =>
            {
                exerciseFleet = this.navalBase.Fleets[m];
                CurrentBattle = new Battle(exerciseFleet, null, CombinedFleetType.None, BattleKind.Normal);
            };

            listener.SortieStarting += (t, m) =>
            {
                sortieFleet = this.navalBase.Fleets[m.FleetId];
                if (m.FleetId == 1 && this.navalBase.CombinedFleet != CombinedFleetType.None)
                {
                    sortieFleet2 = this.navalBase.Fleets[(FleetId)2];
                }
                navalBase.Quests.Knowledges?.OnSortieStart(m.MapId, sortieFleet, sortieFleet2);
            };

            listener.MapRouting += (t, m) =>
            {
                CurrentRouting = new MapRouting(this.navalBase, m);
                CurrentBattle  = new Battle(sortieFleet, sortieFleet2, this.navalBase.CombinedFleet, m.BattleKind);
                navalBase.Quests.Knowledges?.OnMapRouting(CurrentRouting, sortieFleet, sortieFleet2);
            };

            listener.BattleStarted += (t, m) =>
            {
                CurrentBattle.Append(this.navalBase.MasterData, m.Parsed);
            };

            listener.BattleAppended += (t, m) =>
            {
                CurrentBattle.Append(this.navalBase.MasterData, m.Parsed);
            };

            listener.BattleCompleted += (t, m) =>
            {
                CurrentBattleResult = new BattleResult(this.navalBase.MasterData, m, CurrentBattle.Ally);
                if (exerciseFleet is null)
                {
                    navalBase.Quests.Knowledges?.OnBattleComplete(CurrentRouting, CurrentBattle, CurrentBattleResult);
                }
                else
                {
                    navalBase.Quests.Knowledges?.OnExerciseComplete(exerciseFleet, CurrentBattleResult);
                }
            };
        }
コード例 #14
0
 public Admiral(IRawAdmiral raw, NavalBase owner, DateTimeOffset timeStamp) : this(raw.Id, owner) => UpdateProps(raw, timeStamp);
コード例 #15
0
 public Admiral(int id, NavalBase owner) : base(id)
 {
     this.owner = owner;
     CreateDummy();
 }
コード例 #16
0
 public UseItemCount(IRawUseItemCount raw, NavalBase owner, DateTimeOffset timeStamp) : this(raw.Id, owner) => UpdateProps(raw, timeStamp);
コード例 #17
0
 public UseItemCount(UseItemId id, NavalBase owner) : base(id)
 {
     this.owner = owner;
     CreateDummy();
 }
コード例 #18
0
 public RepairingDock(RepairingDockId id, NavalBase owner) : base(id)
 {
     this.owner = owner;
     CreateDummy();
 }
コード例 #19
0
 public MapHPView(NavalBase navalBase)
 {
     ViewModel = navalBase;
     InitializeComponent();
 }
コード例 #20
0
 public BuildingDock(BuildingDockId id, NavalBase owner) : base(id)
 {
     this.owner = owner;
     CreateDummy();
 }
コード例 #21
0
 public BuildingDock(IRawBuildingDock raw, NavalBase owner, DateTimeOffset timeStamp) : this(raw.Id, owner) => UpdateProps(raw, timeStamp);
コード例 #22
0
ファイル: MasterDataView.xaml.cs プロジェクト: wbsdty331/ing
 public MasterDataView(NavalBase navalBase)
 {
     MasterData = navalBase.MasterData;
     this.InitializeComponent();
 }
コード例 #23
0
ファイル: ShipCatalogView.xaml.cs プロジェクト: lyu0912/ing
 public ShipCatalogView(NavalBase navalBase)
 {
     AllShipsView = new AdvancedCollectionView(navalBase.AllShips.DefaultView, isLiveShaping: true);
     InitializeComponent();
 }
コード例 #24
0
 public AdmiralView(NavalBase viewModel)
 {
     ViewModel = viewModel;
     this.InitializeComponent();
 }
コード例 #25
0
 public Ship(ShipId id, NavalBase owner) : base(id)
 {
     this.owner = owner;
     CreateDummy();
 }
コード例 #26
0
ファイル: ExpeditionView.xaml.cs プロジェクト: wbsdty331/ing
 public ExpeditionView(NavalBase viewModel)
 {
     ViewModel = viewModel;
     this.InitializeComponent();
 }
コード例 #27
0
 public DocksView(NavalBase viewModel)
 {
     ViewModel = viewModel;
     this.InitializeComponent();
 }
コード例 #28
0
 public Fleet(FleetId id, NavalBase owner) : base(id)
 {
     this.owner = owner;
     CreateDummy();
 }
コード例 #29
0
ファイル: Logger.cs プロジェクト: wbsdty331/ing
        public Logger(IDataService dataService, IGameProvider provider, NavalBase navalBase)
        {
            this.dataService = dataService;
            this.navalBase   = navalBase;

            provider.EquipmentCreated += (t, m) =>
            {
                using (var context = CreateContext())
                {
                    context.EquipmentCreationTable.Add(new EquipmentCreationEntity
                    {
                        TimeStamp        = t,
                        Consumption      = m.Consumption,
                        EquipmentCreated = m.SelectedEquipentInfoId,
                        IsSuccess        = m.IsSuccess,
                        AdmiralLevel     = this.navalBase.Admiral.Leveling.Level,
                        Secretary        = this.navalBase.Secretary.Info.Id,
                        SecretaryLevel   = this.navalBase.Secretary.Leveling.Level
                    });
                    context.SaveChanges();
                }
            };

            provider.ShipCreated += (t, m) =>
            {
                shipCreation = new ShipCreationEntity
                {
                    TimeStamp      = t,
                    Consumption    = m.Consumption,
                    IsLSC          = m.IsLSC,
                    AdmiralLevel   = this.navalBase.Admiral.Leveling.Level,
                    Secretary      = this.navalBase.Secretary.Info.Id,
                    SecretaryLevel = this.navalBase.Secretary.Leveling.Level
                };
                lastBuildingDock = m.BuildingDockId;
            };

            provider.BuildingDockUpdated += (t, m) =>
            {
                if (shipCreation != null)
                {
                    using (var context = CreateContext())
                    {
                        shipCreation.ShipBuilt      = m.Single(x => x.Id == lastBuildingDock).BuiltShipId.Value;
                        shipCreation.EmptyDockCount = navalBase.BuildingDocks.Count(x => x.State == BuildingDockState.Empty);
                        context.ShipCreationTable.Add(shipCreation);
                        shipCreation     = null;
                        lastBuildingDock = default;
                        context.SaveChanges();
                    }
                }
            };

            provider.ExpeditionCompleted += (t, m) =>
            {
                using (var context = CreateContext())
                {
                    context.ExpeditionCompletionTable.Add(new ExpeditionCompletionEntity
                    {
                        TimeStamp         = t,
                        ExpeditionId      = this.navalBase.Fleets[m.FleetId].Expedition.Id,
                        ExpeditionName    = m.ExpeditionName,
                        Result            = m.Result,
                        MaterialsAcquired = m.MaterialsAcquired,
                        RewardItem1       = m.RewardItem1,
                        RewardItem2       = m.RewardItem2
                    });
                    context.SaveChanges();
                }
            };

#if DEBUG
            using (var context = CreateContext())
                context.Database.Migrate();
#endif

            provider.AdmiralUpdated += (t, m) =>
            {
                if (PlayerLoaded)
                {
                    using (var context = CreateContext())
                        context.Database.Migrate();
                }
            };
        }
コード例 #30
0
 public Fleet(IRawFleet raw, NavalBase owner, DateTimeOffset timeStamp) : this(raw.Id, owner) => UpdateProps(raw, timeStamp);