attrs.go 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. package hero
  2. import (
  3. "f1-game/internal/constant"
  4. "f1-game/internal/data"
  5. "f1-game/internal/enum"
  6. "f1-game/internal/extend/math"
  7. "f1-game/internal/types"
  8. "f1-game/nodes/game/internal/db"
  9. dbHero "f1-game/nodes/game/internal/db/data/hero"
  10. clog "github.com/cherry-game/cherry/logger"
  11. )
  12. type attrsFunc func(playerID int64, heroEntity *dbHero.Hero, attrs *types.Attrs)
  13. var attrsFuncList = []attrsFunc{
  14. heroAttrs,
  15. equipAttrs,
  16. skillAttrs,
  17. }
  18. // 英雄
  19. func heroAttrs(playerID int64, hero *dbHero.Hero, attrs *types.Attrs) {
  20. heroRow, found := data.Hero.GetByID(hero.HeroID)
  21. if !found {
  22. return
  23. }
  24. // 英雄初始(基础值)
  25. attrs.Add(enum.Attr_HP, heroRow.InitHealth)
  26. attrs.Add(enum.Attr_MaxHP, heroRow.InitHealth)
  27. attrs.Add(enum.Attr_MinAttack, heroRow.InitAttack)
  28. attrs.Add(enum.Attr_MaxAttack, heroRow.InitAttack)
  29. attrs.Add(enum.Attr_MinDefense, heroRow.InitDefense)
  30. attrs.Add(enum.Attr_MaxDefense, heroRow.InitDefense)
  31. attrs.Add(enum.Attr_AttackSpeed, heroRow.InitAttackSpeed)
  32. attrs.Add(enum.Attr_Speed, heroRow.InitSpeed)
  33. // TODO 初始攻击距离没加
  34. playerTable, _ := db.GetPlayerTable(playerID)
  35. // 等级成长 策划填的是万分比
  36. if playerTable.Lord.Level > 1 {
  37. frac := int64(playerTable.Lord.Level - 1)
  38. // 成长增加生命值
  39. growHPAdd := heroRow.HealthGrow * frac / constant.RatioBase
  40. attrs.Add(enum.Attr_HP, growHPAdd)
  41. attrs.Add(enum.Attr_MaxHP, growHPAdd)
  42. // 成长增加攻击力
  43. growAddAttack := heroRow.AttackGrow * frac / constant.RatioBase
  44. attrs.Add(enum.Attr_MinAttack, growAddAttack)
  45. attrs.Add(enum.Attr_MaxAttack, growAddAttack)
  46. // 成长增加防御力
  47. growAddDefense := heroRow.DefenseGrow * frac / constant.RatioBase
  48. attrs.Add(enum.Attr_MinDefense, growAddDefense)
  49. attrs.Add(enum.Attr_MaxDefense, growAddDefense)
  50. }
  51. // 星级成长
  52. if hero.Star > 0 {
  53. heroStarAttrRow, ok := data.HeroStarAttrs.GetByHeroIDStar(hero.HeroID, hero.Star)
  54. if ok {
  55. attrs.Add(enum.Attr_HP, heroStarAttrRow.Health)
  56. attrs.Add(enum.Attr_MaxHP, heroStarAttrRow.Health)
  57. attrs.Add(enum.Attr_MinAttack, heroStarAttrRow.Attack)
  58. attrs.Add(enum.Attr_MaxAttack, heroStarAttrRow.Attack)
  59. attrs.Add(enum.Attr_MinDefense, heroStarAttrRow.Defense)
  60. attrs.Add(enum.Attr_MaxDefense, heroStarAttrRow.Defense)
  61. } else {
  62. clog.Warnf("[HeroStarAttrs] config not exists: heroID=%d, star=%d", hero.HeroID, hero.Star)
  63. }
  64. }
  65. }
  66. // 装备增加属性
  67. func equipAttrs(playerID int64, hero *dbHero.Hero, attrs *types.Attrs) {
  68. if hero.EquipGUIDList.Size() <= 0 {
  69. return
  70. }
  71. equipTable := db.GetEquipTable(playerID)
  72. for _, equipGUID := range hero.EquipGUIDList {
  73. equip, found := equipTable.Equips.Get(equipGUID)
  74. if !found {
  75. clog.Warnf("[playerID=%d] HeroEquipAttrs equip not exists: equipGUID=%d", playerID, equipGUID)
  76. continue
  77. }
  78. if equip.WearHeroGUID != hero.GUID {
  79. continue
  80. }
  81. // 添加基础属性
  82. for attrID, attr := range equip.BaseAttrs {
  83. attrs.Add(attrID, attr)
  84. }
  85. // 添加装备附加属性值
  86. for _, attr := range equip.ExtraAttrs {
  87. attrs.Add(attr.Key, attr.Value)
  88. }
  89. // 添加装备等级属性
  90. equipRow, found := data.Equip.GetByID(equip.EquipID)
  91. if !found {
  92. clog.Warnf("[playerID=%d] HeroEquipAttrs equip config not exists: equipID=%d", playerID, equip.EquipID)
  93. continue
  94. }
  95. equipLevelRow, found := data.EquipLevel.GetByQualityLevel(equipRow.Quality, equip.Level)
  96. if !found {
  97. clog.Warnf("[playerID=%d] HeroEquipAttrs equip level config not exists: equipID=%d, level=%d", playerID, equip.EquipID, equip.Level)
  98. continue
  99. }
  100. // 装备强化等级增加基础属性
  101. for attrID, attr := range equip.BaseAttrs {
  102. addAttrValue := math.Round[float64, int64](float64(attr*equipLevelRow.BaseAttrAddPer) / constant.RatioBase)
  103. attrs.Add(attrID, addAttrValue)
  104. }
  105. // TODO 确定装备专属技能是否会增加额外的属性
  106. }
  107. }
  108. // TODO 技能 当前英雄技能没有增加属性
  109. func skillAttrs(_ int64, hero *dbHero.Hero, attrs *types.Attrs) {
  110. }
  111. // 阵型羁绊加成
  112. func lineupFetterAttrs(playerID int64, hero *dbHero.Hero, attrs *types.Attrs, lineupID int32) {
  113. var (
  114. teamTable = db.GetLineupTable(playerID)
  115. )
  116. lineups, found := teamTable.LineupMap.GetLineups(constant.Adventure_Type)
  117. if !found {
  118. return
  119. }
  120. lineup, found := lineups.GetLineup(lineupID)
  121. if !found {
  122. return
  123. }
  124. fetterIDs := lineup.FetterIDs
  125. if fetterIDs.Size() < 1 {
  126. return
  127. }
  128. for fetterID := range fetterIDs {
  129. fetterRow, found := data.HeroFetter.GetByID(fetterID)
  130. if !found {
  131. clog.Warnf("[lineupFetterAttrs] fetter not found, heroID:%d, fetterID: %d", hero.HeroID, fetterID)
  132. continue
  133. }
  134. // 当前羁绊不存在该英雄,则跳过
  135. if !fetterRow.HeroIDs.Contains(hero.HeroID) {
  136. continue
  137. }
  138. curAttrs := fetterRow.GetAttrs()
  139. for attrId, attrValue := range curAttrs {
  140. attrs.Add(attrId, attrValue)
  141. }
  142. }
  143. }