extend_monster.go 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. package data
  2. import (
  3. "f1-game/internal/enum"
  4. "f1-game/internal/pb"
  5. "f1-game/internal/types"
  6. "fmt"
  7. cstring "github.com/cherry-game/cherry/extend/string"
  8. )
  9. type (
  10. MonsterFighter struct {
  11. ID int64 `json:"id"`
  12. BattleObjType int32 `json:"battleObjType"`
  13. ConfigID int32 `json:"configID"`
  14. Attrs types.Attrs `json:"attrs"`
  15. Skills []uint32 `json:"skills"`
  16. Level int32 `json:"level"`
  17. TroopsAttrs types.Attrs `json:"troopsAttrs"`
  18. }
  19. )
  20. // 怪物fighter转换为proto
  21. func (p *MonsterFighter) ToProto() (*pb.Fighter, *pb.Attrs) {
  22. return &pb.Fighter{
  23. Id: p.ID,
  24. BattleObjType: p.BattleObjType,
  25. ConfigID: p.ConfigID,
  26. Attrs: p.Attrs.ToProto(),
  27. Skills: p.Skills,
  28. Level: p.Level,
  29. }, p.TroopsAttrs.ToProto()
  30. }
  31. // 获取怪物属性
  32. func (p *MonsterRow) GetAttrs() types.Attrs {
  33. attrs := types.NewAttrs()
  34. attrs.Set(enum.Attr_Speed, p.Speed)
  35. attrs.Set(enum.Attr_MinAttack, p.MinAttack)
  36. attrs.Set(enum.Attr_MaxAttack, p.MaxAttack)
  37. attrs.Set(enum.Attr_AttackSpeed, p.AttackSpeed)
  38. attrs.Set(enum.Attr_MinDefense, p.MinDefense)
  39. attrs.Set(enum.Attr_MaxDefense, p.MaxDefense)
  40. attrs.Set(enum.Attr_HP, p.Hp)
  41. attrs.Set(enum.Attr_MaxHP, p.Hp)
  42. attrs.Set(enum.Attr_CriticalHitChance, p.CriticalHitChance)
  43. attrs.Set(enum.Attr_CriticalHitResistance, p.CriticalHitResistance)
  44. attrs.Set(enum.Attr_CriticalHitDamage, p.CriticalHitDamage)
  45. attrs.Set(enum.Attr_CriticalHitDamageResistance, p.CriticalHitDamageResistance)
  46. attrs.Set(enum.Attr_Luck, p.Luck)
  47. attrs.Set(enum.Attr_DamageBonus, p.DamageBonus)
  48. attrs.Set(enum.Attr_DamageReduction, p.DamageReduction)
  49. return attrs
  50. }
  51. // 获取怪物属性
  52. func (p *MonsterRow) GetTroopsAttrs() types.Attrs {
  53. attrs := types.NewAttrs()
  54. attrs.Set(enum.Attr_SquadAttackBonus, p.SquadAttackBonus)
  55. attrs.Set(enum.Attr_SquadHealthBonus, p.SquadHealthBonus)
  56. return attrs
  57. }
  58. // 构建局内战斗技能 局内技能=局外技能ID+技能等级
  59. func (p *MonsterRow) buildBattleSkill() []uint32 {
  60. var skillList []uint32
  61. for _, skill := range p.SkillLevels {
  62. skillList = append(skillList, uint32(skill.Key+skill.Value))
  63. }
  64. return skillList
  65. }
  66. // 构建怪物fighter
  67. func (p *MonsterRow) buildMonsterFighter(groupID int32, index int32) *MonsterFighter {
  68. // 组ID+位置+MonsterID 组装成唯一怪物ID
  69. idStr := fmt.Sprintf("%04v%02v%04v", groupID, index, p.ID)
  70. return &MonsterFighter{
  71. ID: cstring.ToInt64D(idStr),
  72. BattleObjType: enum.BattleObjType_Monster,
  73. ConfigID: p.ID,
  74. Attrs: p.GetAttrs(), // 属性列表
  75. Skills: p.buildBattleSkill(), // 场内技能列表
  76. Level: p.Level,
  77. TroopsAttrs: p.GetTroopsAttrs(),
  78. }
  79. }