1
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 战斗角色
|
||||
/// </summary>
|
||||
public class BattleCharacter : DataAttribute {
|
||||
/// <summary> 角色数据 </summary>
|
||||
public readonly DataCharacter character;
|
||||
|
||||
/// <summary> 角色名字 </summary>
|
||||
public string name;
|
||||
/// <summary> 战斗等级 </summary>
|
||||
public int level;
|
||||
/// <summary> 生命点 </summary>
|
||||
public int hitPoint;
|
||||
/// <summary> 护甲等级 </summary>
|
||||
public int armorClass;
|
||||
/// <summary> 先攻顺序 </summary>
|
||||
public int sequence;
|
||||
|
||||
public BattleCharacter(DataCharacter character) {
|
||||
this.character = character;
|
||||
Cover(character);
|
||||
name = character.name;
|
||||
level = character.Level;
|
||||
hitPoint = character.HitPoint;
|
||||
armorClass = character.ArmorClass;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b4cb406221da1364f97a333bf1e3442c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,40 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 战斗队列
|
||||
/// </summary>
|
||||
public class BattleQueue {
|
||||
/// <summary> 执行队列 </summary>
|
||||
public Queue<BattleCharacter> queue = new Queue<BattleCharacter>();
|
||||
/// <summary> 战斗合集 </summary>
|
||||
public List<BattleCharacter> characters = new List<BattleCharacter>();
|
||||
|
||||
/// <summary> 添加角色 </summary>
|
||||
public void Add(List<BattleCharacter> list) {
|
||||
characters.AddRange(list);
|
||||
}
|
||||
/// <summary> 添加角色 </summary>
|
||||
public void Add(BattleCharacter character) {
|
||||
characters.Add(character);
|
||||
}
|
||||
/// <summary> 先攻:d20 + 敏捷调整值 </summary>
|
||||
public void Sequence() {
|
||||
characters.ForEach(obj => obj.sequence = Dice.Roll20(obj.DexModifier));
|
||||
}
|
||||
/// <summary> 排序:大到小 </summary>
|
||||
public void OrderByDescending() {
|
||||
characters = characters.OrderByDescending(c => c.sequence).ToList();
|
||||
}
|
||||
/// <summary> 回合 </summary>
|
||||
public void Reset() {
|
||||
queue = new Queue<BattleCharacter>(characters);
|
||||
}
|
||||
/// <summary> 当前行动者 </summary>
|
||||
public bool Current(out BattleCharacter battle) {
|
||||
battle = queue.Count > 0 ? queue.Dequeue() : null;
|
||||
return battle != null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ed7fc5b50e619ea4a8eaf9d71dc0ec9d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,5 +1,8 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Palmmedia.ReportGenerator.Core;
|
||||
using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
@@ -31,7 +34,73 @@ public class BattleSimulator {
|
||||
|
||||
// 哥布林射手死亡
|
||||
|
||||
public BattleSimulator() {
|
||||
/// <summary> 回合计数 </summary>
|
||||
public int roundCount;
|
||||
/// <summary> 行动间隔 </summary>
|
||||
public float interval;
|
||||
/// <summary> 最大间隔 </summary>
|
||||
public float maxInterval = 1f;
|
||||
/// <summary> 当前行动 </summary>
|
||||
public Action currentAction;
|
||||
/// <summary> 队伍1 </summary>
|
||||
public BattleTeam team1;
|
||||
/// <summary> 队伍2 </summary>
|
||||
public BattleTeam team2;
|
||||
/// <summary> 战斗队列 </summary>
|
||||
public BattleQueue battleQueue = new BattleQueue();
|
||||
|
||||
public BattleSimulator(List<DataCharacter> cha1, List<DataCharacter> cha2) {
|
||||
List<BattleCharacter> bCha1 = new List<BattleCharacter>();
|
||||
cha1.ForEach(obj => bCha1.Add(new BattleCharacter(obj)));
|
||||
List<BattleCharacter> bCha2 = new List<BattleCharacter>();
|
||||
cha2.ForEach(obj => bCha2.Add(new BattleCharacter(obj)));
|
||||
|
||||
team1 = new BattleTeam(bCha1);
|
||||
team2 = new BattleTeam(bCha2);
|
||||
|
||||
battleQueue.Add(bCha1);
|
||||
battleQueue.Add(bCha2);
|
||||
battleQueue.Sequence();
|
||||
battleQueue.OrderByDescending();
|
||||
|
||||
currentAction = UpdateRound;
|
||||
}
|
||||
public void Update() {
|
||||
if (interval > 0) { interval -= Time.deltaTime; return; }
|
||||
currentAction?.Invoke();
|
||||
}
|
||||
|
||||
/// <summary> 更新回合 </summary>
|
||||
public void UpdateRound() {
|
||||
roundCount++;
|
||||
battleQueue.Reset();
|
||||
Debug.Log($"正式回合 {roundCount}");
|
||||
|
||||
interval = maxInterval;
|
||||
currentAction = SelectActionTarget;
|
||||
}
|
||||
/// <summary> 选择行动对象 </summary>
|
||||
public void SelectActionTarget() {
|
||||
if (!battleQueue.Current(out BattleCharacter character)) {
|
||||
currentAction = UpdateRound; return;
|
||||
}
|
||||
Debug.Log($"当前 {character.name}({character.sequence}) 行动");
|
||||
|
||||
interval = maxInterval;
|
||||
currentAction = SelectActionTarget;
|
||||
}
|
||||
public void SelectAttackTarget(BattleCharacter character) {
|
||||
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 战斗队伍
|
||||
/// </summary>
|
||||
public class BattleTeam {
|
||||
|
||||
public List<BattleCharacter> characters;
|
||||
|
||||
public BattleTeam(List<BattleCharacter> characters) {
|
||||
this.characters = characters;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user