雖然現在很多遊戲都用上手動戰鬥了,但還是想分享一下之前做過的回合制遊戲的戰鬥資料寫法。不同遊戲戰鬥有不同的寫法,資料上的需求也會有些差異,下面這個回合制戰鬥資料包當是借鑒,它滿足很多的戰鬥需求比如:多場戰鬥連在一起打,合擊,群攻,消除buffer,反擊等等。
typedef uint8_t CellId;
typedef uint16_t CardId;
typedef uint16_t CAttr;
typedef uint16_t SkillId;
typedef uint16_t BufferId;
typedef uint16_t ComId;
typedef json::value JsonValue;
typedef ByteData ByteValue;
namespace GameBattle
{
struct BackAttack //反擊技能被攻擊對象
{
CellId cellId; //被攻擊對象的站位
bool isAvoid; //是否閃避
CAttr hp; //血量值變化
CAttr energy; //能量值變化
BackAttack();
void convertToJson(JsonValue& val) const;
void convertFromJson(const JsonValue& val);
void Serialize(ByteValue& val) const;
void DeSerialize(const ByteValue& val);
};
struct ActionObject //作用的對象
{
CellId cellId; //被作用的對象站位
bool isAvoid; //是否閃避
CAttr hp; //血量值變化
CAttr energy; //能量值變化
ComId comId; //可以是技能也可以是bufferId
vector<BackAttack> backAttacks; //反擊技能對象
vector<BufferId> deleteBuffers; //消除的buffer
ActionObject();
void convertToJson(JsonValue& val) const;
void convertFromJson(const JsonValue& val);
void Serialize(ByteValue& val) const;
void DeSerialize(const ByteValue& val);
};
struct SubAttack
{
CellId cellId; //攻擊對象站位
bool isCrit; //是否暴擊
SkillId skillId; //釋放的技能ID
CAttr costEnergy; //釋放技能消耗的能量
vector<ActionObject> objs; //作用的對象集合
SubAttack();
void convertToJson(JsonValue& val) const;
void convertFromJson(const JsonValue& val);
void Serialize(ByteValue& val) const;
void DeSerialize(const ByteValue& val);
};
struct OneAttack
{
vector<SubAttack> attacks; //攻擊集合
OneAttack();
void convertToJson(JsonValue& val) const;
void convertFromJson(const JsonValue& val);
void Serialize(ByteValue& val) const;
void DeSerialize(const ByteValue& val);
};
struct BufferObject
{
CellId cellId; //作用的站位對象
BufferId bufferId; //bufferId
CAttr hp; //變化的血量值
CAttr energy; //變化的能量值
BufferObject();
void convertToJson(JsonValue& val) const;
void convertFromJson(const JsonValue& val);
void Serialize(ByteValue& val) const;
void DeSerialize(const ByteValue& val);
};
struct OneRound
{
vector<BufferObject> buffers; //每回合初始時的buffer效果
vector<OneAttack> attacks; //每次攻擊集合
OneRound();
void convertToJson(JsonValue& val) const;
void convertFromJson(const JsonValue& val);
void Serialize(ByteValue& val) const;
void DeSerialize(const ByteValue& val);
};
struct BattleCell
{
CellId cellId; //站位ID
CardId cardId; //卡牌ID
CAttr curHp; //目前血量
CAttr maxHp; //最大血量
CAttr curEnergy; //目前能量值
CAttr maxEnergy; //最大能量值
BattleCell();
void convertToJson(JsonValue& val) const;
void convertFromJson(const JsonValue& val);
void Serialize(ByteValue& val) const;
void DeSerialize(const ByteValue& val);
};
struct OneBattle
{
PlayerId winner; //赢者ID
PlayerId atkId; //攻擊者ID
PlayerId atkedId;//被攻擊者ID
vector<BattleCell> lineup; //陣型
vector<BufferObject> recovers;//每場戰鬥後的能量和血量加成效果
vector<OneRound> rounds;//戰鬥回合集合
OneBattle();
void convertToJson(JsonValue& val) const;
void convertFromJson(const JsonValue& val);
void Serialize(ByteValue& val) const;
void DeSerialize(const ByteValue& val);
};
struct BattleResult
{
string battleId; //每場戰鬥ID
vector<OneBattle> battles; //每場戰鬥集合
BattleResult();
void convertToJson(JsonValue& val) const;
void convertFromJson(const JsonValue& val);
void Serialize(ByteValue& val) const;
void DeSerialize(const ByteValue& val);
};
}