Skip to content
This repository has been archived by the owner on May 18, 2023. It is now read-only.

Commit

Permalink
艦隊
Browse files Browse the repository at this point in the history
・簡易火力計算の追加対応
・フレッチャー砲対空カットインの文字列修正
・夜間瑞雲攻撃対応
戦闘
・2023春イベント 航空支援付き潜水部隊マス対応
  • Loading branch information
yosxpeee committed Mar 1, 2023
1 parent 5d6cea7 commit c66718b
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 78 deletions.
10 changes: 6 additions & 4 deletions ElectronicObserver/Data/Battle/BattleManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,9 @@ public int PredictWinRank(out double friendrate, out double enemyrate)

enemybefore += initial;
enemyafter += Math.Max(result, 0);
enemycount++;
//攻撃できない敵艦はカウント外とする
if (firstInitial.IsEnemyTargetable[i] == true)
enemycount++;

if (result <= 0)
enemysunk++;
Expand All @@ -669,7 +671,9 @@ public int PredictWinRank(out double friendrate, out double enemyrate)

enemybefore += initial;
enemyafter += Math.Max(result, 0);
enemycount++;
//攻撃できない敵艦はカウント外とする
if (firstInitial.IsEnemyTargetableEscort[i] == true)
enemycount++;

if (result <= 0)
enemysunk++;
Expand All @@ -688,10 +692,8 @@ public int PredictWinRank(out double friendrate, out double enemyrate)
else
return GetWinRank(friendcount, enemycount, friendsunk, enemysunk, friendrate, enemyrate,
friend[0].HPRate <= 0.25, resultHPs[BattleIndex.EnemyMain1] <= 0);

}


/// <summary>
/// 勝利ランクを計算します。連合艦隊は情報が少ないので正確ではありません。
/// </summary>
Expand Down
57 changes: 50 additions & 7 deletions ElectronicObserver/Data/Battle/Phase/PhaseInitial.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ public class PhaseInitial : PhaseBase
public int[] EnemyMaxHPs { get; private set; }
public int[] EnemyMaxHPsEscort { get; private set; }


public bool[] IsEnemyTargetable { get; }
public bool[] IsEnemyTargetableEscort { get; }

/// <summary>
/// 敵艦のスロット
Expand Down Expand Up @@ -137,7 +138,31 @@ public PhaseInitial(BattleData data, string title)
FriendFleetID = 1;


int[] GetArrayOrDefault(string objectName, int length) => !RawData.IsDefined(objectName) ? null : FixedArray((int[])RawData[objectName], length);
int[] GetArrayOrDefault(string objectName, int length)
{
object[]? values = RawData.IsDefined(objectName) switch
{
true => RawData[objectName].Deserialize<object[]>(),
_ => null,
};

if (values == null) return null;

int[] cleanedValues = values
.Select(v => v switch
{
double d => (int?)d,
int i => i,
string => -2,
_ => null,
})
.Where(v => v is not null)
.Select(v => v!.Value)
.ToArray();

return FixedArray(cleanedValues, length);
}

int[][] GetArraysOrDefault(string objectName, int topLength, int bottomLength)
{
if (!RawData.IsDefined(objectName))
Expand All @@ -155,9 +180,28 @@ int[][] GetArraysOrDefault(string objectName, int topLength, int bottomLength)
return ret;
}

int[]? HandleTargetability(int[]? hps, ShipDataMaster[] ships, bool[] isTargetable)
{
if (hps is null) return null;

for (int i = 0; i < hps.Length; i++)
{
if (hps[i] is not -2) continue;

isTargetable[i] = false;
Console.WriteLine("{0}:{1}",i, isTargetable[i]);
hps[i] = ships[i].HPMax;
}

return hps;
}

int mainMemberCount = 7;
int escortMemberCount = 6;

IsEnemyTargetable = new[] { true, true, true, true, true, true, true };
IsEnemyTargetableEscort = new[] { true, true, true, true, true, true };

EnemyMembers = GetArrayOrDefault("api_ship_ke", mainMemberCount);
EnemyMembersInstance = EnemyMembers.Select(id => KCDatabase.Instance.MasterShips[id]).ToArray();

Expand All @@ -169,14 +213,13 @@ int[][] GetArraysOrDefault(string objectName, int topLength, int bottomLength)

FriendInitialHPs = GetArrayOrDefault("api_f_nowhps", mainMemberCount);
FriendInitialHPsEscort = GetArrayOrDefault("api_f_nowhps_combined", escortMemberCount);
EnemyInitialHPs = GetArrayOrDefault("api_e_nowhps", mainMemberCount);
EnemyInitialHPsEscort = GetArrayOrDefault("api_e_nowhps_combined", escortMemberCount);
EnemyInitialHPs = HandleTargetability(GetArrayOrDefault("api_e_nowhps", mainMemberCount), EnemyMembersInstance, IsEnemyTargetable);
EnemyInitialHPsEscort = HandleTargetability(GetArrayOrDefault("api_e_nowhps_combined", escortMemberCount), EnemyMembersEscortInstance, IsEnemyTargetableEscort);

FriendMaxHPs = GetArrayOrDefault("api_f_maxhps", mainMemberCount);
FriendMaxHPsEscort = GetArrayOrDefault("api_f_maxhps_combined", escortMemberCount);
EnemyMaxHPs = GetArrayOrDefault("api_e_maxhps", mainMemberCount);
EnemyMaxHPsEscort = GetArrayOrDefault("api_e_maxhps_combined",escortMemberCount);

EnemyMaxHPs = HandleTargetability(GetArrayOrDefault("api_e_maxhps", mainMemberCount), EnemyMembersInstance, IsEnemyTargetable);
EnemyMaxHPsEscort = HandleTargetability(GetArrayOrDefault("api_e_maxhps_combined", escortMemberCount), EnemyMembersEscortInstance, IsEnemyTargetableEscort);

EnemySlots = GetArraysOrDefault("api_eSlot", mainMemberCount, 5);
EnemySlotsInstance = EnemySlots.Select(part => part.Select(id => KCDatabase.Instance.MasterEquipments[id]).ToArray()).ToArray();
Expand Down
9 changes: 7 additions & 2 deletions ElectronicObserver/Resource/Record/ShipParameterRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1025,7 +1025,6 @@ private void AlbumOpened(string apiname, dynamic data)
/// </summary>
private void BattleStart(string apiname, dynamic data)
{

var battle = KCDatabase.Instance.Battle.FirstBattle;
var binit = battle.Initial;

Expand All @@ -1037,7 +1036,13 @@ void UpdateParams(int id, int maxhp, int[] status, int[] slot)
param = new ShipParameterElement { ShipID = id };
}

param.HPMin = param.HPMax = maxhp;
param.HPMin = param.HPMax = maxhp switch

This comment has been minimized.

Copy link
@myangelkamikaze

myangelkamikaze Mar 2, 2023

This part isn't needed anymore, -2 gets removed in HandleTargetability. In the first implementation, I didn't use HandleTargetability, so that workaround was needed.
Was removed here: ElectronicObserverEN@1db89e1

This comment has been minimized.

Copy link
@yosxpeee

yosxpeee Mar 7, 2023

Author Owner

Thank you for pointing this out.
I will correct it in the next update.

{
// hack: -2 is used as a magic number for untargetable enemies
// don't use that value to update the master data
-2 => param.HPMax,
_ => maxhp,
};

if (status != null)
{
Expand Down
2 changes: 1 addition & 1 deletion ElectronicObserver/Utility/SoftwareInformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static class SoftwareInformation
/// <summary>
/// 更新日時
/// </summary>
public static DateTime UpdateTime => DateTimeHelper.CSVStringToTime("2023/02/18 13:00:00");
public static DateTime UpdateTime => DateTimeHelper.CSVStringToTime("2023/03/01 21:00:00");

private static System.Net.WebClient client;
private static readonly Uri uri = new Uri("https://raw.githubusercontent.com/yosxpeee/ElectronicObserver/develop/ElectronicObserver/version.txt");
Expand Down
25 changes: 2 additions & 23 deletions ElectronicObserver/Window/Control/ShipStatusHP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,12 @@ namespace ElectronicObserver.Window.Control
{
public partial class ShipStatusHP : UserControl
{


private const TextFormatFlags TextFormatTime = TextFormatFlags.NoPadding | TextFormatFlags.Bottom | TextFormatFlags.HorizontalCenter;
private const TextFormatFlags TextFormatText = TextFormatFlags.NoPadding | TextFormatFlags.Bottom | TextFormatFlags.Left;
private const TextFormatFlags TextFormatHP = TextFormatFlags.NoPadding | TextFormatFlags.Bottom | TextFormatFlags.Right;

private static readonly Size MaxSize = new Size(int.MaxValue, int.MaxValue);
private const string SlashText = " / ";

public bool IsTargetable { get; set; } = true;

private StatusBarModule _HPBar;

Expand Down Expand Up @@ -357,9 +354,6 @@ private Size RepairTimeSizeCache

#endregion




public ShipStatusHP()
{
InitializeComponent();
Expand Down Expand Up @@ -389,19 +383,14 @@ public ShipStatusHP()
_showDifference = false;
_repairTimeShowMode = ShipStatusHPRepairTimeShowMode.Invisible;
_showHPBar = true;

}


private void ShipStatusHP_Paint(object sender, PaintEventArgs e)
{

Graphics g = e.Graphics;
Rectangle basearea = new Rectangle(Padding.Left, Padding.Top, Width - Padding.Horizontal, Height - Padding.Vertical);
Size barSize = ShowHPBar ? _HPBar.GetPreferredSize(new Size(basearea.Width, 0)) : Size.Empty;



if (RepairTimeShowMode == ShipStatusHPRepairTimeShowMode.Visible ||
(RepairTimeShowMode == ShipStatusHPRepairTimeShowMode.MouseOver && _onMouse))
{
Expand All @@ -415,11 +404,9 @@ private void ShipStatusHP_Paint(object sender, PaintEventArgs e)
font = SubFont;

TextRenderer.DrawText(g, timestr, font, rect, RepairFontColor, TextFormatTime);

}
else
{

Point p = new Point(basearea.X, basearea.Bottom - barSize.Height - Math.Max(TextSizeCache.Height, MaximumValueSizeCache.Height) + 1);
TextRenderer.DrawText(g, Text, SubFont, new Rectangle(p, TextSizeCache), SubFontColor, TextFormatText);
//g.DrawRectangle( Pens.Orange, new Rectangle( p, TextSizeCache ) );
Expand All @@ -436,15 +423,12 @@ private void ShipStatusHP_Paint(object sender, PaintEventArgs e)
p.Y = basearea.Bottom - barSize.Height - ValueSizeCache.Height + 1;
TextRenderer.DrawText(g, Math.Max(Value, 0).ToString(), MainFont, new Rectangle(p, ValueSizeCache), MainFontColor, TextFormatHP);
//g.DrawRectangle( Pens.Orange, new Rectangle( p, ValueSizeCache ) );

}

if (ShowHPBar)
_HPBar.Paint(g, new Rectangle(basearea.X, basearea.Bottom - barSize.Height, barSize.Width, barSize.Height));
_HPBar.Paint(g, new Rectangle(basearea.X, basearea.Bottom - barSize.Height, barSize.Width, barSize.Height), IsTargetable);
}



public override Size GetPreferredSize(Size proposedSize)
{

Expand All @@ -461,8 +445,6 @@ public override Size GetPreferredSize(Size proposedSize)
return _preferredSizeCache.Value;
}



private void PropertyChanged()
{
if (!IsRefreshSuspended)
Expand All @@ -478,7 +460,6 @@ private void PropertyChanged()
}
}


private static Color FromArgb(uint color)
{
return Color.FromArgb(unchecked((int)color));
Expand All @@ -503,10 +484,8 @@ private void ShipStatusHP_MouseLeave(object sender, EventArgs e)
if (RepairTimeShowMode == ShipStatusHPRepairTimeShowMode.MouseOver)
PropertyChanged();
}

}


public enum ShipStatusHPRepairTimeShowMode
{
Invisible,
Expand Down
10 changes: 2 additions & 8 deletions ElectronicObserver/Window/Control/ShipStatusResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ private void PropertyChanged()
Invalidate();
}


/// <summary>
/// 資源を一度に設定します。
/// </summary>
Expand All @@ -110,17 +109,12 @@ public void SetResources(int fuelCurrent, int fuelMax, int ammoCurrent, int ammo
PropertyChanged();
}



private void ShipStatusResource_Paint(object sender, PaintEventArgs e)
{

const int margin = 3;

BarFuel.Paint(e.Graphics, new Rectangle(0, margin, this.Width, BarFuel.GetPreferredSize().Height));
BarAmmo.Paint(e.Graphics, new Rectangle(0, this.Height - margin - BarFuel.GetPreferredSize().Height, this.Width, BarFuel.GetPreferredSize().Height));

BarFuel.Paint(e.Graphics, new Rectangle(0, margin, this.Width, BarFuel.GetPreferredSize().Height), true);
BarAmmo.Paint(e.Graphics, new Rectangle(0, this.Height - margin - BarFuel.GetPreferredSize().Height, this.Width, BarFuel.GetPreferredSize().Height), true);
}

}
}
56 changes: 33 additions & 23 deletions ElectronicObserver/Window/Control/StatusBarModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ private static Color BlendColor(Color a, Color b, double weight)
/// </summary>
/// <param name="g">描画するための Graphics。</param>
/// <param name="rect">描画する領域。</param>
public void Paint(Graphics g, Rectangle rect)
public void Paint(Graphics g, Rectangle rect, bool isTargatable)
{

using (var b = new SolidBrush(BarColorBackground))
Expand All @@ -441,33 +441,43 @@ public void Paint(Graphics g, Rectangle rect)

if (!ColorMorphing)
{

if (p <= 0.25)
barColor = BarColor0Begin;
else if (p <= 0.50)
barColor = BarColor1Begin;
else if (p <= 0.75)
barColor = BarColor2Begin;
else if (p < 1.00)
barColor = BarColor3Begin;
if (!isTargatable)
{
barColor = _barColorBackground;
}
else
barColor = BarColor4;

{
if (p <= 0.25)
barColor = BarColor0Begin;
else if (p <= 0.50)
barColor = BarColor1Begin;
else if (p <= 0.75)
barColor = BarColor2Begin;
else if (p < 1.00)
barColor = BarColor3Begin;
else
barColor = BarColor4;
}
}
else
{

if (p <= 0.25)
barColor = BlendColor(BarColor0Begin, BarColor0End, p * 4.0);
else if (p <= 0.50)
barColor = BlendColor(BarColor1Begin, BarColor1End, (p - 0.25) * 4.0);
else if (p <= 0.75)
barColor = BlendColor(BarColor2Begin, BarColor2End, (p - 0.50) * 4.0);
else if (p < 1.00)
barColor = BlendColor(BarColor3Begin, BarColor3End, (p - 0.75) * 4.0);
if (!isTargatable)
{
barColor = _barColorBackground;
}
else
barColor = BarColor4;

{
if (p <= 0.25)
barColor = BlendColor(BarColor0Begin, BarColor0End, p * 4.0);
else if (p <= 0.50)
barColor = BlendColor(BarColor1Begin, BarColor1End, (p - 0.25) * 4.0);
else if (p <= 0.75)
barColor = BlendColor(BarColor2Begin, BarColor2End, (p - 0.50) * 4.0);
else if (p < 1.00)
barColor = BlendColor(BarColor3Begin, BarColor3End, (p - 0.75) * 4.0);
else
barColor = BarColor4;
}
}

using (var b = new SolidBrush(barColor))
Expand Down
Loading

0 comments on commit c66718b

Please sign in to comment.