forked from yuyuvn/KanColleViewer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockyard.cs
113 lines (96 loc) · 2.73 KB
/
Dockyard.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive.Linq;
using System.Threading.Tasks;
using Grabacr07.KanColleWrapper.Internal;
using Grabacr07.KanColleWrapper.Models;
using Grabacr07.KanColleWrapper.Models.Raw;
using Livet;
namespace Grabacr07.KanColleWrapper
{
/// <summary>
/// 複数の建造ドックを持つ工廠を表します。
/// </summary>
public class Dockyard : NotificationObject
{
#region Dock 変更通知プロパティ
private MemberTable<BuildingDock> _Docks;
public MemberTable<BuildingDock> Docks
{
get { return this._Docks; }
set
{
if (this._Docks != value)
{
this._Docks = value;
this.RaisePropertyChanged();
}
}
}
#endregion
#region CreatedSlotItem 変更通知プロパティ
private CreatedSlotItem _CreatedSlotItem;
/// <summary>
/// 最後に開発された装備アイテムの情報を取得します。
/// </summary>
public CreatedSlotItem CreatedSlotItem
{
get { return this._CreatedSlotItem; }
private set
{
if (this._CreatedSlotItem != value)
{
this._CreatedSlotItem = value;
this.RaisePropertyChanged();
}
}
}
#endregion
internal Dockyard(KanColleProxy proxy)
{
this.Docks = new MemberTable<BuildingDock>();
proxy.api_get_member_kdock.TryParse<kcsapi_kdock[]>().Subscribe(x => this.Update(x.Data));
proxy.api_req_kousyou_getship.TryParse<kcsapi_kdock_getship>().Subscribe(x => this.GetShip(x.Data));
proxy.api_req_kousyou_createship_speedchange.TryParse().Subscribe(this.ChangeSpeed);
proxy.api_req_kousyou_createitem.TryParse<kcsapi_createitem>().Subscribe(this.CreateSlotItem);
}
internal void Update(kcsapi_kdock[] source)
{
if (this.Docks.Count == source.Length)
{
foreach (var raw in source)
{
var target = this.Docks[raw.api_id];
if (target != null) target.Update(raw);
}
}
else
{
this.Docks.ForEach(x => x.Value.Dispose());
this.Docks = new MemberTable<BuildingDock>(source.Select(x => new BuildingDock(x)));
}
}
private void GetShip(kcsapi_kdock_getship source)
{
this.Update(source.api_kdock);
}
private void ChangeSpeed(SvData svd)
{
try
{
var dock = this.Docks[int.Parse(svd.Request["api_kdock_id"])];
var highspeed = svd.Request["api_highspeed"] == "1";
if (highspeed) dock.Finish();
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine("高速建造材使用の解析に失敗しました: {0}", ex);
}
}
private void CreateSlotItem(SvData<kcsapi_createitem> svd)
{
this.CreatedSlotItem = new CreatedSlotItem(svd.Data);
}
}
}