意图初步
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Continentis.MainGame.Card;
|
||||
using Continentis.MainGame.Equipment;
|
||||
using SLSFramework.General;
|
||||
@@ -278,4 +279,136 @@ namespace Continentis.MainGame.Character
|
||||
target.characterView.hudContainer.UpdateAllHUD();
|
||||
}
|
||||
}
|
||||
|
||||
public partial class CharacterBase
|
||||
{
|
||||
public virtual void RegisterIntention(params IntentionBase[] intentions)
|
||||
{
|
||||
intentionSubmodule.allIntentions.AddRange(intentions);
|
||||
}
|
||||
|
||||
public virtual void IntentionBrain()
|
||||
{
|
||||
List<IntentionBase> availableIntentions = intentionSubmodule.allIntentions.Where(intention => intention.Condition()).ToList();
|
||||
availableIntentions.Sort();
|
||||
intentionSubmodule.currentIntention = availableIntentions.FirstOrDefault() ?? new IntentionBase(intentionSubmodule);
|
||||
intentionSubmodule.currentIntention.RefreshCardWeights();
|
||||
intentionSubmodule.currentIntention.RefreshTargets();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user