BU.lua 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. require("battle.Unit")
  2. local ReceiverBase = require("core:erm.ReceiverBase")
  3. local BU = ReceiverBase:new()
  4. function BU:new(ERM)
  5. return ReceiverBase.new(self,{ERM = ERM})
  6. end
  7. local BattleLogMessage = require("netpacks.BattleLogMessage")
  8. local BattleUnitsChanged = require("netpacks.BattleUnitsChanged")
  9. local battle = BATTLE
  10. function BU:C(x, p1)
  11. assert(type(p1) == "nil", "!!BU:C can only check value")
  12. local ret = battle:isFinished()
  13. if type(ret) == "nil" then
  14. return 0
  15. else
  16. return 1
  17. end
  18. end
  19. function BU:D(x, hex, p1)
  20. assert(type(p1) == "nil", "!!BU:D can only check value")
  21. local unit = battle:getUnitByPos(hex, false)
  22. if unit then
  23. if unit:isAlive() then
  24. return nil, -2
  25. else
  26. return nil, unit:unitId()
  27. end
  28. else
  29. return nil, -1
  30. end
  31. end
  32. function BU:E(x, hex, p1)
  33. assert(type(p1) == "nil", "!!BU:E can only check value")
  34. local unit = battle:getUnitByPos(hex, false)
  35. if unit and unit:isAlive() then
  36. return nil, unit:unitId()
  37. else
  38. return nil, -1
  39. end
  40. end
  41. local SPECIAL_FIELDS = {}
  42. SPECIAL_FIELDS['sand_shore'] = 0
  43. SPECIAL_FIELDS['cursed_ground'] = 1
  44. SPECIAL_FIELDS['magic_plains'] = 2
  45. SPECIAL_FIELDS['holy_ground'] = 3
  46. SPECIAL_FIELDS['evil_fog'] = 4
  47. SPECIAL_FIELDS['clover_field'] = 5
  48. SPECIAL_FIELDS['lucid_pools'] = 6
  49. SPECIAL_FIELDS['fiery_fields'] = 7
  50. SPECIAL_FIELDS['rocklands'] = 8
  51. SPECIAL_FIELDS['magic_clouds'] = 9
  52. function BU:G(x, p1)
  53. assert(type(p1) == "nil", "!!BU:G? is not implemented")
  54. local bfield = SPECIAL_FIELDS[battle:getBattlefieldType()]
  55. if bfield then
  56. return bfield
  57. else
  58. return -1
  59. end
  60. end
  61. function BU:M(x, message)
  62. local pack = BattleLogMessage.new()
  63. pack:addText(message)
  64. SERVER:addToBattleLog(pack)
  65. end
  66. function BU:O(x, ...)
  67. error("!!BU:O is not implemented")
  68. end
  69. function BU:R(x, ...)
  70. error("!!BU:R is not implemented")
  71. end
  72. function BU:S(x, typ, count, hex, side, slot)
  73. local pack = BattleUnitsChanged.new()
  74. local id = battle:getNextUnitId()
  75. pack:add(id,
  76. {
  77. newUnitInfo =
  78. {
  79. ["count"] = count,
  80. ["type"] = typ,
  81. ["side"] = side,
  82. ["position"] = hex,
  83. ["summoned"] = (slot == -1),
  84. }
  85. })
  86. SERVER:changeUnits(pack)
  87. end
  88. function BU:T(x)
  89. local tacticDistance = battle:getTacticDistance()
  90. if tacticDistance == 0 then
  91. return 0
  92. else
  93. return 1
  94. end
  95. end
  96. function BU:V(x, ...)
  97. error("!!BU:V is not implemented")
  98. end
  99. return BU