2025-05-13 19:22:01 +08:00

182 lines
4.2 KiB
C#

using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using Godot;
using Godot.Bridge;
using Godot.Collections;
using Godot.NativeInterop;
[GlobalClass]
[ScriptPath("res://Scripts/Resources/BulletConds.cs")]
public partial class BulletConds : Resource
{
public enum HPPercentCheck
{
Average,
OnlyOne
}
[Export(PropertyHint.None, "")]
public int weight = 1;
[Export(PropertyHint.None, "")]
public int lastAct = -1;
[Export(PropertyHint.None, "")]
public int onlyOnTurn = -1;
[Export(PropertyHint.None, "")]
public int order = -1;
[Export(PropertyHint.None, "")]
public int orderLimit = 9999;
[Export(PropertyHint.None, "")]
public int everyXTurns = -1;
[Export(PropertyHint.None, "")]
public int turnBelow = -1;
[Export(PropertyHint.None, "")]
public int turnAbove = -1;
[Export(PropertyHint.None, "")]
public float hpPercentGreater = -1f;
[Export(PropertyHint.None, "")]
public float hpPercentLower = -1f;
[Export(PropertyHint.None, "")]
public Array<Entity.IDs> neededGroup;
[Export(PropertyHint.None, "")]
public bool exactMatch;
[Export(PropertyHint.None, "")]
public bool special;
[ExportSubgroup("Flags", "")]
[Export(PropertyHint.None, "")]
public Array<SaveFile.Flags> need;
[Export(PropertyHint.None, "")]
public Array<SaveFile.Flags> limit;
[Export(PropertyHint.None, "")]
public Array<StringName> battleFlagNeed;
[Export(PropertyHint.None, "")]
public Array<StringName> battleFlagLimit;
[Export(PropertyHint.None, "")]
public Array<StringName> internalNeeds;
[Export(PropertyHint.None, "")]
public Array<StringName> internalLimit;
[Export(PropertyHint.None, "")]
public Array<StringName> setInternal;
public bool CanDo(Battlers caller = null)
{
if (special)
{
return false;
}
if (onlyOnTurn > -1 && BattleDR.current.turn != onlyOnTurn)
{
return false;
}
if (order > -1 && (int)Main.Repeat(BattleDR.current.turn, orderLimit) != order)
{
return false;
}
if (everyXTurns > 0 && BattleDR.current.turn % everyXTurns != 0)
{
return false;
}
if (turnBelow > -1 && BattleDR.current.turn > turnBelow)
{
return false;
}
if (turnAbove > -1 && BattleDR.current.turn < turnAbove)
{
return false;
}
Array<Entity.IDs> array = neededGroup;
if (array != null && array.Count > 0)
{
List<Entity.IDs> h = new List<Entity.IDs>();
if (BattleDR.current.enemies.Count < neededGroup.Count)
{
return false;
}
for (int i = 0; i < BattleDR.current.enemies.Count; i++)
{
h.Add(BattleDR.current.enemies[i].entity.id);
}
if (exactMatch && BattleDR.current.enemies.Count != neededGroup.Count)
{
return false;
}
if (!neededGroup.All((Entity.IDs x) => h.Remove(x)))
{
return false;
}
}
if (need != null && need.Count != 0 && SaveFile.HasFlags(need))
{
return false;
}
if (limit != null && limit.Count != 0 && !SaveFile.HasFlags(limit))
{
return false;
}
Array<StringName> array2 = battleFlagNeed;
if (array2 != null && array2.Count > 0 && !battleFlagNeed.All((StringName x) => BattleDR.current.tempFlags.Contains(x)))
{
return false;
}
Array<StringName> array3 = battleFlagLimit;
if (array3 != null && array3.Count > 0 && battleFlagLimit.All((StringName x) => BattleDR.current.tempFlags.Contains(x)))
{
return false;
}
if (caller != null)
{
if (lastAct > -1 && !caller.lastestAct.Contains(lastAct))
{
return false;
}
if (hpPercentGreater > 0f && caller.HPPercent() < hpPercentGreater)
{
return false;
}
if (hpPercentLower > 0f && caller.HPPercent() > hpPercentLower)
{
return false;
}
Array<StringName> array4 = internalNeeds;
if (array4 != null && array4.Count > 0 && !internalNeeds.All((StringName x) => caller.internalFlags.Contains(x)))
{
return false;
}
Array<StringName> array5 = internalLimit;
if (array5 != null && array5.Count > 0 && internalLimit.All((StringName x) => caller.internalFlags.Contains(x)))
{
return false;
}
Array<StringName> array6 = setInternal;
if (array6 != null && array6.Count > 0)
{
for (int num = 0; num < setInternal.Count; num++)
{
caller.internalFlags.Add(setInternal[num]);
}
}
}
return true;
}
}