意图初步
This commit is contained in:
@@ -4,6 +4,7 @@ using System.Linq;
|
||||
using Continentis.MainGame.Card;
|
||||
using Continentis.MainGame.Combat;
|
||||
using NaughtyAttributes;
|
||||
using SLSFramework.UModAssistance;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
using Random = UnityEngine.Random;
|
||||
@@ -28,6 +29,7 @@ namespace Continentis.MainGame.Character
|
||||
public Guid elementID { get; set; }
|
||||
|
||||
public CharacterData data;
|
||||
public CharacterLogicBase logicBase;
|
||||
|
||||
public Fraction fraction;
|
||||
public CombatTeam team;
|
||||
@@ -54,13 +56,17 @@ namespace Continentis.MainGame.Character
|
||||
|
||||
[ShowNativeProperty]
|
||||
public CombatBuffSubmodule combatBuffSubmodule { get; private set; }
|
||||
|
||||
[ShowNativeProperty]
|
||||
public RecordSubmodule recordSubmodule { get; private set; }
|
||||
|
||||
public void Initialize(Fraction fraction)
|
||||
public virtual void Initialize(Fraction fraction, CharacterData data)
|
||||
{
|
||||
(this as IGameElement).Initialize();
|
||||
|
||||
this.fraction = fraction;
|
||||
|
||||
this.data = data;
|
||||
|
||||
switch (fraction)
|
||||
{
|
||||
case Fraction.Player:
|
||||
@@ -81,6 +87,33 @@ namespace Continentis.MainGame.Character
|
||||
intentionSubmodule = new IntentionSubmodule(this);
|
||||
statusSubmodule = new StatusSubmodule(this);
|
||||
combatBuffSubmodule = new CombatBuffSubmodule(this);
|
||||
recordSubmodule = new RecordSubmodule(this);
|
||||
|
||||
this.logicBase = GenerateCharacterLogic(data);
|
||||
this.logicBase.Initialize(this);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 生成卡牌逻辑实例
|
||||
/// </summary>
|
||||
public static CharacterLogicBase GenerateCharacterLogic(CharacterData data)
|
||||
{
|
||||
string typeID = ModManager.GetTypeID(data.modName, "Characters", "", data.className);
|
||||
Type logicType = ModManager.GetType(typeID);
|
||||
|
||||
if(logicType == null)
|
||||
{
|
||||
return new CharacterLogicBase();
|
||||
}
|
||||
|
||||
if (Activator.CreateInstance(logicType) is CharacterLogicBase logic)
|
||||
{
|
||||
return logic;
|
||||
}
|
||||
|
||||
Debug.LogError($"Card class '{typeID}' not found or could not be instantiated.");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,124 +121,6 @@ namespace Continentis.MainGame.Character
|
||||
{
|
||||
public CombatCharacterViewBase characterView;
|
||||
}
|
||||
|
||||
public partial class CharacterBase
|
||||
{
|
||||
public virtual void GetIntendedCards()
|
||||
{
|
||||
bool CanAfford(CardInstance card, int stamina, int mana)
|
||||
{
|
||||
return card.cardLogic.GetAttribute("StaminaCost") <= stamina &&
|
||||
card.cardLogic.GetAttribute("ManaCost") <= mana;
|
||||
}
|
||||
|
||||
bool CheckAvailabilityAndSetTargets(CardInstance card, out List<CharacterBase> targets)
|
||||
{
|
||||
card.cardLogic.DetectTargetsValidity(out List<CharacterBase> valid, out _, out _);
|
||||
if (valid.Count == 0 || !card.cardLogic.CheckBeforePlay())
|
||||
{
|
||||
targets = null;
|
||||
return false; // 无有效目标或无法使用则跳过
|
||||
}
|
||||
|
||||
targets = card.cardLogic.SetRandomTargets(valid);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
IntentionBase currentIntention = intentionSubmodule.currentIntention;
|
||||
List<CardInstance> availableCards = deckSubmodule.PoolPile;
|
||||
List<IntendedCard> intended = new List<IntendedCard>();
|
||||
int currentStamina = GetAttribute("Stamina");
|
||||
int remainingStamina = currentStamina - currentIntention.guaranteedStamina;
|
||||
int currentMana = GetAttribute("Mana");
|
||||
int remainingMana = currentMana - currentIntention.guaranteedMana;
|
||||
|
||||
List<CardInstance> forced = new List<CardInstance>();
|
||||
List<CardInstance> normal = new List<CardInstance>();
|
||||
|
||||
foreach (CardInstance card in availableCards)
|
||||
{
|
||||
if (card.cardLogic.weightSubmodule.forceUse)
|
||||
{
|
||||
forced.Add(card);
|
||||
}
|
||||
else
|
||||
{
|
||||
normal.Add(card);
|
||||
}
|
||||
}
|
||||
|
||||
intentionSubmodule.intendedCards.Clear();
|
||||
//(characterView.hudContainer.enablingHUDs["Intention"] as Intention)?.Clear();
|
||||
|
||||
// 1. 优先处理强制选择卡牌
|
||||
foreach (CardInstance card in forced)
|
||||
{
|
||||
if (currentIntention.maxCardCount > 0 && intended.Count >= currentIntention.maxCardCount)
|
||||
{
|
||||
break; // 已达数量上限
|
||||
}
|
||||
|
||||
if (CanAfford(card, remainingStamina, remainingMana))
|
||||
{
|
||||
if(!CheckAvailabilityAndSetTargets(card, out List<CharacterBase> targets))
|
||||
{
|
||||
continue; // 无有效目标或无法使用则跳过
|
||||
}
|
||||
|
||||
intended.Add(new IntendedCard(card, targets));
|
||||
remainingStamina -= card.cardLogic.GetAttribute("StaminaCost");
|
||||
remainingMana -= card.cardLogic.GetAttribute("ManaCost");
|
||||
}
|
||||
// 行动力不足则跳过该卡
|
||||
}
|
||||
|
||||
// 2. 在剩余普通卡牌中基于权重随机选取
|
||||
while (intended.Count < currentIntention.maxCardCount)
|
||||
{
|
||||
// 筛选出当前资源下还能出的牌
|
||||
List<CardInstance> affordableCards = normal.FindAll(card => CanAfford(card, remainingStamina, remainingMana));
|
||||
|
||||
if (affordableCards.Count == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
float totalWeight = affordableCards.Sum(card => card.cardLogic.weightSubmodule.currentWeight);
|
||||
if (totalWeight <= 0f) break;
|
||||
|
||||
float r = Random.value * totalWeight;
|
||||
float accum = 0f;
|
||||
CardInstance chosen = null;
|
||||
foreach (CardInstance card in affordableCards)
|
||||
{
|
||||
accum += card.cardLogic.weightSubmodule.currentWeight;
|
||||
if (r <= accum)
|
||||
{
|
||||
chosen = card;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (chosen != null)
|
||||
{
|
||||
if (!CheckAvailabilityAndSetTargets(chosen, out List<CharacterBase> targets))
|
||||
{
|
||||
normal.Remove(chosen);
|
||||
continue; // 无有效目标或无法使用则跳过
|
||||
}
|
||||
|
||||
intended.Add(new IntendedCard(chosen, targets));
|
||||
normal.Remove(chosen);
|
||||
remainingStamina -= chosen.cardLogic.GetAttribute("StaminaCost");
|
||||
remainingMana -= chosen.cardLogic.GetAttribute("ManaCost");
|
||||
}
|
||||
}
|
||||
|
||||
intentionSubmodule.intendedCards.AddRange(intended);
|
||||
}
|
||||
}
|
||||
|
||||
public partial class CharacterBase
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user