extend_equip.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package data
  2. import (
  3. "f1-game/internal/extend/rand"
  4. "f1-game/internal/types"
  5. )
  6. // 获取附加属性的数量
  7. func (p *EquipRow) GetExtraAttrNum() int32 {
  8. totalProp := int32(0)
  9. for _, prop := range p.RandomAttrNumRange {
  10. totalProp += prop.Value
  11. }
  12. randNum := rand.RangeInt(0, totalProp)
  13. curProp := int32(0)
  14. for _, prop := range p.RandomAttrNumRange {
  15. curProp += prop.Value
  16. if randNum <= curProp {
  17. return prop.Key
  18. }
  19. }
  20. return 0
  21. }
  22. // 随机技能池
  23. func (p *EquipRow) RandomSingleSkillPool() int32 {
  24. totalProp := int32(0)
  25. for _, skillPool := range p.RandomSkillPools {
  26. totalProp += skillPool.Value
  27. }
  28. var (
  29. randValue = rand.RangeInt(0, totalProp)
  30. curProp = int32(0)
  31. )
  32. for _, skillPool := range p.RandomSkillPools {
  33. curProp += skillPool.Value
  34. if randValue <= curProp {
  35. return skillPool.Key
  36. }
  37. }
  38. return 0
  39. }
  40. func (p *EquipRow) CalEquipCraftCosts(num int64) types.Assets {
  41. needCosts := types.Assets{}
  42. for _, cost := range p.CraftCosts {
  43. needCosts.Add(cost.ID, cost.Num*num)
  44. }
  45. return needCosts
  46. }