| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- package data
- import (
- "f1-game/internal/enum"
- "f1-game/internal/pb"
- "f1-game/internal/types"
- "fmt"
- cstring "github.com/cherry-game/cherry/extend/string"
- )
- type (
- MonsterFighter struct {
- ID int64 `json:"id"`
- BattleObjType int32 `json:"battleObjType"`
- ConfigID int32 `json:"configID"`
- Attrs types.Attrs `json:"attrs"`
- Skills []uint32 `json:"skills"`
- Level int32 `json:"level"`
- TroopsAttrs types.Attrs `json:"troopsAttrs"`
- }
- )
- // 怪物fighter转换为proto
- func (p *MonsterFighter) ToProto() (*pb.Fighter, *pb.Attrs) {
- return &pb.Fighter{
- Id: p.ID,
- BattleObjType: p.BattleObjType,
- ConfigID: p.ConfigID,
- Attrs: p.Attrs.ToProto(),
- Skills: p.Skills,
- Level: p.Level,
- }, p.TroopsAttrs.ToProto()
- }
- // 获取怪物属性
- func (p *MonsterRow) GetAttrs() types.Attrs {
- attrs := types.NewAttrs()
- attrs.Set(enum.Attr_Speed, p.Speed)
- attrs.Set(enum.Attr_MinAttack, p.MinAttack)
- attrs.Set(enum.Attr_MaxAttack, p.MaxAttack)
- attrs.Set(enum.Attr_AttackSpeed, p.AttackSpeed)
- attrs.Set(enum.Attr_MinDefense, p.MinDefense)
- attrs.Set(enum.Attr_MaxDefense, p.MaxDefense)
- attrs.Set(enum.Attr_HP, p.Hp)
- attrs.Set(enum.Attr_MaxHP, p.Hp)
- attrs.Set(enum.Attr_CriticalHitChance, p.CriticalHitChance)
- attrs.Set(enum.Attr_CriticalHitResistance, p.CriticalHitResistance)
- attrs.Set(enum.Attr_CriticalHitDamage, p.CriticalHitDamage)
- attrs.Set(enum.Attr_CriticalHitDamageResistance, p.CriticalHitDamageResistance)
- attrs.Set(enum.Attr_Luck, p.Luck)
- attrs.Set(enum.Attr_DamageBonus, p.DamageBonus)
- attrs.Set(enum.Attr_DamageReduction, p.DamageReduction)
- return attrs
- }
- // 获取怪物属性
- func (p *MonsterRow) GetTroopsAttrs() types.Attrs {
- attrs := types.NewAttrs()
- attrs.Set(enum.Attr_SquadAttackBonus, p.SquadAttackBonus)
- attrs.Set(enum.Attr_SquadHealthBonus, p.SquadHealthBonus)
- return attrs
- }
- // 构建局内战斗技能 局内技能=局外技能ID+技能等级
- func (p *MonsterRow) buildBattleSkill() []uint32 {
- var skillList []uint32
- for _, skill := range p.SkillLevels {
- skillList = append(skillList, uint32(skill.Key+skill.Value))
- }
- return skillList
- }
- // 构建怪物fighter
- func (p *MonsterRow) buildMonsterFighter(groupID int32, index int32) *MonsterFighter {
- // 组ID+位置+MonsterID 组装成唯一怪物ID
- idStr := fmt.Sprintf("%04v%02v%04v", groupID, index, p.ID)
- return &MonsterFighter{
- ID: cstring.ToInt64D(idStr),
- BattleObjType: enum.BattleObjType_Monster,
- ConfigID: p.ID,
- Attrs: p.GetAttrs(), // 属性列表
- Skills: p.buildBattleSkill(), // 场内技能列表
- Level: p.Level,
- TroopsAttrs: p.GetTroopsAttrs(),
- }
- }
|