Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
andanteyk committed Aug 27, 2016
2 parents 2ceda55 + e9758b1 commit b23b03d
Show file tree
Hide file tree
Showing 56 changed files with 3,781 additions and 575 deletions.
Binary file modified ElectronicObserver/Assets.zip
Binary file not shown.
Binary file added ElectronicObserver/Assets/Form/BaseAirCorps.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ElectronicObserver/Assets/Form/Json.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ElectronicObserver/Assets/Parameter/AircraftCost.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
175 changes: 175 additions & 0 deletions ElectronicObserver/Data/BaseAirCorpsData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ElectronicObserver.Data {

/// <summary>
/// 基地航空隊のデータを扱います。
/// </summary>
[DebuggerDisplay( "[{AirCorpsID}] {Name}" )]
public class BaseAirCorpsData : APIWrapper, IIdentifiable {



/// <summary>
/// 航空隊ID
/// </summary>
public int AirCorpsID {
get {
return (int)RawData.api_rid;
}
}

/// <summary>
/// 航空隊名
/// </summary>
public string Name {
get {
return RawData.api_name;
}
private set {
RawData.api_name = value;
}
}

/// <summary>
/// 戦闘行動半径
/// </summary>
public int Distance {
get {
return (int)RawData.api_distance;
}
private set {
RawData.api_distance = value;
}
}

/// <summary>
/// 行動指示
/// 0=待機, 1=出撃, 2=防空, 3=退避, 4=休息
/// </summary>
public int ActionKind {
get {
return (int)RawData.api_action_kind;
}
private set {
RawData.api_action_kind = value;
}
}


/// <summary>
/// 航空中隊情報
/// </summary>
public IDDictionary<BaseAirCorpsSquadron> Squadrons { get; private set; }

public BaseAirCorpsSquadron this[int i] {
get {
return Squadrons[i];
}
}

/// <summary>
/// 配置転換中の装備固有IDリスト
/// </summary>
public static HashSet<int> RelocatedEquipments { get; private set; }


static BaseAirCorpsData() {
RelocatedEquipments = new HashSet<int>();
}


public BaseAirCorpsData() {
Squadrons = new IDDictionary<BaseAirCorpsSquadron>();
}


public override void LoadFromRequest( string apiname, Dictionary<string, string> data ) {
base.LoadFromRequest( apiname, data );

switch ( apiname ) {
case "api_req_air_corps/change_name":
Name = data["api_name"];
break;

case "api_req_air_corps/set_action": {

int[] ids = data["api_base_id"].Split( ",".ToCharArray() ).Select( s => int.Parse( s ) ).ToArray();
int[] actions = data["api_action_kind"].Split( ",".ToCharArray() ).Select( s => int.Parse( s ) ).ToArray();

int index = Array.IndexOf( ids, AirCorpsID );

if ( index >= 0 ) {
ActionKind = actions[index];
}

} break;
}
}

public override void LoadFromResponse( string apiname, dynamic data ) {

switch ( apiname ) {
case "api_get_member/base_air_corps":
default:
base.LoadFromResponse( apiname, (object)data );

SetSquadrons( apiname, data.api_plane_info );
break;

case "api_req_air_corps/set_plane": {
var prev = Squadrons.Values.Select( sq => sq != null ? sq.EquipmentMasterID : 0 ).ToArray();
SetSquadrons( apiname, data.api_plane_info );

foreach ( var deleted in prev.Except( Squadrons.Values.Select( sq => sq != null && sq.State == 1 ? sq.EquipmentMasterID : 0 ) ) ) {
var eq = KCDatabase.Instance.Equipments[deleted];

if ( eq != null ) {
eq.RelocatedTime = DateTime.Now;
BaseAirCorpsData.RelocatedEquipments.Add( deleted );
}
}

Distance = (int)data.api_distance;
} break;

case "api_req_air_corps/supply":
SetSquadrons( apiname, data.api_plane_info );
break;
}
}

private void SetSquadrons( string apiname, dynamic data ) {

foreach ( var elem in data ) {

int id = (int)elem.api_squadron_id;

if ( !Squadrons.ContainsKey( id ) ) {
var a = new BaseAirCorpsSquadron();
a.LoadFromResponse( apiname, elem );
Squadrons.Add( a );

} else {
Squadrons[id].LoadFromResponse( apiname, elem );
}
}
}


public static void SetRelocatedEquipments( IEnumerable<int> values ) {
if ( values != null )
RelocatedEquipments = new HashSet<int>( values );
}

public int ID {
get { return AirCorpsID; }
}
}
}
129 changes: 129 additions & 0 deletions ElectronicObserver/Data/BaseAirCorpsSquadron.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ElectronicObserver.Data {

/// <summary>
/// 基地航空隊の航空中隊データを扱います。
/// </summary>
[DebuggerDisplay( "{EquipmentInstance} {AircraftCurrent}/{AircraftMax}" )]
public class BaseAirCorpsSquadron : APIWrapper, IIdentifiable {

/// <summary>
/// 中隊ID
/// </summary>
public int SquadronID {
get {
return (int)RawData.api_squadron_id;
}
}

/// <summary>
/// 状態
/// 0=未配属, 1=配属済み, 2=配置転換中
/// </summary>
public int State {
get {
return RawData.api_state() ? (int)RawData.api_state : 0;
}
}

/// <summary>
/// 装備固有ID
/// </summary>
public int EquipmentMasterID {
get {
return (int)RawData.api_slotid;
}
}

/// <summary>
/// 装備データ
/// </summary>
public EquipmentData EquipmentInstance {
get {
return KCDatabase.Instance.Equipments[EquipmentMasterID];
}
}

/// <summary>
/// 装備ID
/// </summary>
public int EquipmentID {
get {
var eq = EquipmentInstance;
return eq != null ? eq.EquipmentID : -1;
}
}

/// <summary>
/// マスター装備データ
/// </summary>
public EquipmentDataMaster EquipmentInstanceMaster {
get {
var eq = EquipmentInstance;
return eq != null ? eq.MasterEquipment : null;
}
}

/// <summary>
/// 現在の稼働機数
/// </summary>
public int AircraftCurrent {
get {
return RawData.api_count() ? (int)RawData.api_count : 0;
}
}

/// <summary>
/// 最大機数
/// </summary>
public int AircraftMax {
get {
return RawData.api_max_count() ? (int)RawData.api_max_count : 0;
}
}

/// <summary>
/// コンディション
/// 1=通常、2=橙疲労、3=赤疲労
/// </summary>
public int Condition {
get {
return RawData.api_cond() ? (int)RawData.api_cond : 1;
}
}


/// <summary>
/// 配置転換を開始した時刻
/// </summary>
public DateTime RelocatedTime { get; private set; }


public override void LoadFromResponse( string apiname, dynamic data ) {

int prevState = RawData != null ? State : 0;

base.LoadFromResponse( apiname, (object)data );

// 配置転換中になったとき
if ( prevState == 1 && State == 2 ) {
RelocatedTime = DateTime.Now;
}

if ( State != 2 ) {
RelocatedTime = DateTime.MinValue;
}
}


public int ID {
get { return SquadronID; }
}
}
}
Loading

0 comments on commit b23b03d

Please sign in to comment.