equipment.go 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. package conv
  2. /*import (
  3. "encoding/json"
  4. "gadmin/package/gmdata"
  5. "gadmin/utility"
  6. "github.com/pkg/errors"
  7. "github.com/sirupsen/logrus"
  8. "leafstalk/covenant/model"
  9. "os"
  10. )
  11. var Equipment = new(cEquipment)
  12. type EquipInfo struct {
  13. BodyId int `json:"bodyId"`
  14. ID int `json:"id"`
  15. Name string `json:"name"`
  16. Description string `json:"description"`
  17. Star int `json:"star"`
  18. MaxLevel int `json:"equiplev"`
  19. Def string `json:"def_UP"` // 减伤加成
  20. Price int `json:"price"`
  21. Skill []int `json:"skill"`
  22. NextSkill []int `json:"nextSkill"`
  23. DecomposeMaterials [][2]int64 `json:"deco_material"`
  24. Materials [][2]int64 `json:"material"`
  25. }
  26. type EquipMaterials struct {
  27. BodyId int `json:"bodyId"`
  28. Level int `json:"level"`
  29. Materials [][2]int64 `json:"material"`
  30. }
  31. type cEquipment struct {
  32. version string
  33. radio float64
  34. lst []*gmdata.Equipment
  35. }
  36. func (j *cEquipment) Extract(version string) {
  37. logrus.Info("cEquipment Extract...")
  38. // 获取地址:https://demograve.mg.xhgame.com/json/v1.4.9/base_data.json 取值:equipment_disassemble_ratio
  39. j.radio = float64(1)
  40. j.setVersion(version).convert()
  41. }
  42. func (j *cEquipment) setVersion(version string) *cEquipment {
  43. j.version = version
  44. return j
  45. }
  46. func (j *cEquipment) loadJson(fileName string, v interface{}) error {
  47. b, err := GetUrlBody(j.version, fileName)
  48. if err != nil {
  49. return errors.Errorf("loadJson GetUrlBody err:%+v", err)
  50. }
  51. if err := json.Unmarshal(b, v); err != nil {
  52. return errors.Errorf("Unmarshal err=%v", err)
  53. }
  54. return nil
  55. }
  56. func (j *cEquipment) convert() *cEquipment {
  57. typeInfo := map[int]string{1: "weapons.json", 2: "head.json", 3: "body.json", 4: "belt.json", 5: "feet.json", 6: "hand.json"}
  58. // 武器,穿戴一共6个分类
  59. allEquipments := make(map[int][]*model.EquipmentAttr)
  60. // 武器
  61. var weapons []EquipInfo
  62. if err := j.loadJson("Weapons.json", &weapons); err != nil {
  63. panic(err)
  64. }
  65. // 装备
  66. var wears []EquipInfo
  67. if err := j.loadJson("Wear.json", &wears); err != nil {
  68. panic(err)
  69. }
  70. // 所有装备升级材料
  71. var updateInfos []EquipMaterials
  72. if err := j.loadJson("EquipmentMaterials.json", &updateInfos); err != nil {
  73. panic(err)
  74. }
  75. upgradeCategoryMap := map[int][]EquipMaterials{}
  76. upgradeMap := map[int]EquipMaterials{}
  77. for _, v := range updateInfos {
  78. upgradeCategoryMap[v.BodyId] = append(upgradeCategoryMap[v.BodyId], v)
  79. upgradeMap[v.BodyId*1000+v.Level] = v
  80. }
  81. maxStarInfo := map[int]int{}
  82. for _, v := range weapons {
  83. if v.ID == 0 {
  84. continue
  85. }
  86. if maxStarInfo[v.BodyId*100+v.ID] < v.Star {
  87. maxStarInfo[v.BodyId*100+v.ID] = v.Star
  88. }
  89. }
  90. for _, v := range wears {
  91. if v.ID == 0 {
  92. continue
  93. }
  94. if maxStarInfo[v.BodyId*100+v.ID] < v.Star {
  95. maxStarInfo[v.BodyId*100+v.ID] = v.Star
  96. }
  97. }
  98. infos := append(weapons, wears...)
  99. for _, v := range infos { // 所有装备进行遍历
  100. for ilevel := 1; ilevel <= v.MaxLevel; ilevel++ {
  101. pId := v.BodyId
  102. // if v.BodyId == 2 {
  103. // pId = 3
  104. // } else if v.BodyId == 3 {
  105. // pId = 2
  106. // }
  107. item := &model.EquipmentAttr{
  108. ID: int64(pId*10_000_000 + v.ID*100_000 + v.Star*1_000 + ilevel),
  109. Star: v.Star,
  110. //Level: uint(ilevel),
  111. //Material: v.ID,
  112. //WearPart: v.BodyId,
  113. Price: v.Price,
  114. Name: v.Name,
  115. }
  116. if item.Star < maxStarInfo[pId*100+v.ID] {
  117. item.NextStar = int64(pId*10_000_000 + v.ID*100_000 + (v.Star+1)*1_000 + ilevel)
  118. }
  119. //if item.Level < uint(v.MaxLevel) {
  120. // item.NextLevel = int64(pId*10_000_000 + v.ID*100_000 + (v.Star)*1_000 + ilevel + 1)
  121. //}
  122. //if item.Level > 1 {
  123. // upgradeInfo := upgradeMap[v.BodyId*1000+int(item.Level)]
  124. // for _, v2 := range upgradeInfo.Materials {
  125. // item.Cost = append(item.Cost, &model.DropMaterial{ID: v2[0], Count: v2[1]})
  126. // }
  127. //} else {
  128. // if item.Level == 1 {
  129. // for _, v2 := range v.DecomposeMaterials {
  130. // item.Cost = append(item.Cost, &model.DropMaterial{ID: v2[0], Count: v2[1]})
  131. // }
  132. // }
  133. //}
  134. extraInfo := map[int64]int64{}
  135. //for _, v2 := range upgradeCategoryMap[v.BodyId] {
  136. // if v2.Level <= int(item.Level) {
  137. // for _, v3 := range v2.Materials {
  138. // extraInfo[v3[0]] += v3[1]
  139. // }
  140. // }
  141. //}
  142. //radio
  143. for k, v := range extraInfo {
  144. extraInfo[k] = int64(float64(v) * j.radio)
  145. }
  146. for _, v2 := range v.DecomposeMaterials {
  147. extraInfo[v2[0]] += v2[1]
  148. }
  149. for k, v2 := range extraInfo {
  150. item.Extract = append(item.Extract, &model.DropMaterial{ID: k, Count: int(v2)})
  151. }
  152. if item.Extract[0].ID != 1001 {
  153. item.Extract[0], item.Extract[1] = item.Extract[1], item.Extract[0]
  154. }
  155. allEquipments[v.BodyId] = append(allEquipments[v.BodyId], item)
  156. }
  157. }
  158. for k, v := range typeInfo {
  159. filePath2 := utility.LocalJsonPath(j.version, v)
  160. logrus.Print("Equipment convert filePath2:"+filePath2, "\r\n")
  161. equipFile2, err := os.Create(filePath2)
  162. if err != nil {
  163. logrus.Errorln("写日志文件失败", err)
  164. }
  165. encoder := json.NewEncoder(equipFile2)
  166. var data []*model.EquipmentAttr
  167. for _, v := range allEquipments[k] {
  168. data = append(data, v)
  169. }
  170. if err = encoder.Encode(data); err != nil {
  171. logrus.Infoln("Encoder failed", err.Error())
  172. } else {
  173. logrus.Infoln("Encoder success")
  174. }
  175. equipFile2.Close()
  176. }
  177. return j
  178. }*/