Advertisement
Guest User

SGsummonbeserker.lua

a guest
May 25th, 2015
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.78 KB | None | 0 0
  1. require("stategraphs/commonstates")
  2.  
  3. local actionhandlers = {
  4. ActionHandler(ACTIONS.EAT, "eat"),
  5. ActionHandler(ACTIONS.CHOP, "chop")
  6. }
  7.  
  8. local attacks_til_groundpound = 4
  9.  
  10. local function onattackfn(inst)
  11. if inst.components.health ~= nil and
  12. not inst.components.health:IsDead() and
  13. (inst.sg:HasStateTag("hit") or not inst.sg:HasStateTag("busy")) then
  14.  
  15. if (attacks_til_groundpound - 1) <= 0 then
  16.  
  17. inst.cangroundpound = true
  18.  
  19. else
  20.  
  21. attacks_til_groundpound = attacks_til_groundpound - 1
  22.  
  23. end
  24.  
  25. if inst.cangroundpound then
  26. inst.sg:GoToState("pound")
  27. else
  28. inst.sg:GoToState("attack")
  29. end
  30. end
  31. end
  32.  
  33. local events = {
  34. CommonHandlers.OnStep(),
  35. CommonHandlers.OnLocomote(true, false),
  36. CommonHandlers.OnDeath(),
  37. EventHandler("attacked", function(inst)
  38. if not inst.components.health:IsDead() and not inst.sg:HasStateTag("attack") then
  39. inst.sg:GoToState("hit")
  40. end
  41. end),
  42. EventHandler("doattack", onattackfn),
  43. EventHandler("doaction", function(inst, data)
  44. if not inst.components.health:IsDead() and not inst.sg:HasStateTag("busy") then
  45. if data.action == ACTIONS.CHOP then
  46. inst.sg:GoToState("chop", data.target)
  47. end
  48. end
  49. end)
  50. }
  51.  
  52. local function ShakeIfClose(inst)
  53. for i, v in ipairs(AllPlayers) do
  54. v:ShakeCamera(CAMERASHAKE.FULL, .7, .02, .3, inst, 40)
  55. end
  56. end
  57.  
  58. local states = {
  59. State {
  60. name= "idle",
  61. tags = {"idle"},
  62. onenter = function(inst)
  63. inst.Physics:Stop()
  64. end,
  65. events = {
  66. EventHandler("animover", function(inst)
  67. inst.sg:GoToState("idle")
  68. end)
  69. }
  70. },
  71. State {
  72. name = "death",
  73. tags = {"busy"},
  74. onenter = function(inst)
  75. inst.SoundEmitter:PlaySound("dontstarve/wilson/death")
  76. inst.AnimState:PlayAnimation("death")
  77. inst.Physics:Stop()
  78. RemovePhysicsColliders(inst)
  79. inst.components.lootdropper:DropLoot(Vector3(inst.Transform:GetWorldPosition()))
  80. end
  81. },
  82. State {
  83. name = "run_start",
  84. tags = {"moving", "running", "canrotate"},
  85. onenter = function(inst)
  86. inst.components.locomotor:RunForward()
  87. inst.AnimState:PlayAnimation("run_pre")
  88. inst.sg.mem.foosteps = 0
  89. end,
  90. events = {
  91. EventHandler("animover", function(inst)
  92. inst.sg:GoToState("run")
  93. end)
  94. },
  95. timeline = {
  96. TimeEvent(4*FRAMES, function(inst)
  97. PlayFootstep(inst)
  98. DoFoleySounds(inst)
  99. end)
  100. }
  101. },
  102. State {
  103. name = "run",
  104. tags = {"moving", "running", "canrotate"},
  105. onenter = function(inst)
  106. inst.components.locomotor:RunForward()
  107. inst.AnimState:PlayAnimation("run_loop")
  108. end,
  109. timeline = {
  110. TimeEvent(7*FRAMES, function(inst)
  111. inst.sg.mem.foosteps = inst.sg.mem.foosteps + 1
  112. PlayFootstep(inst, inst.sg.mem.foosteps < 5 and 1 or .6)
  113. DoFoleySounds(inst)
  114. end),
  115. TimeEvent(15*FRAMES, function(inst)
  116. inst.sg.mem.foosteps = inst.sg.mem.foosteps + 1
  117. PlayFootstep(inst, inst.sg.mem.foosteps < 5 and 1 or .6)
  118. DoFoleySounds(inst)
  119. end)
  120. },
  121. events = {
  122. EventHandler("animover", function(inst)
  123. inst.sg:GoToState("run")
  124. end)
  125. }
  126. },
  127. State {
  128. name = "run_stop",
  129. tags = {"canrotate", "idle"},
  130. onenter = function(inst)
  131. inst.Physics:Stop()
  132. inst.AnimState:PlayAnimation("run_pst")
  133. end,
  134. events = {
  135. EventHandler("animover", function(inst)
  136. inst.sg:GoToState("idle")
  137. end),
  138. },
  139. },
  140. State {
  141. name = "attack",
  142. tags = {"attack"},
  143. onenter = function(inst)
  144. --inst.SoundEmitter:PlaySound("dontstarve/wilson/hit")
  145. inst.components.combat:StartAttack()
  146. inst.Physics:Stop()
  147. inst.AnimState:PlayAnimation("atk")
  148. end,
  149. timeline = {
  150. TimeEvent(13*FRAMES, function(inst)
  151. inst.components.combat:DoAttack()
  152. end),
  153. },
  154. events = {
  155. EventHandler("animover", function(inst)
  156. inst.sg:GoToState("idle")
  157. end),
  158. },
  159. },
  160. State{
  161. name = "pound",
  162. tags = {"attack", "busy"},
  163.  
  164. onenter = function(inst)
  165. --if GoToStandState(inst, "bi") then
  166. inst.components.inventory:Unequip( EQUIPSLOTS.HANDS )
  167. if inst.components.locomotor then
  168. inst.components.locomotor:StopMoving()
  169. end
  170. inst.AnimState:PlayAnimation("punch")
  171. inst:DoTaskInTime(1, function (inst) inst.components.inventory:Equip( inst.sword ) end )
  172. --end
  173. end,
  174.  
  175. timeline=
  176. {
  177. TimeEvent(17*FRAMES, function(inst) inst.SoundEmitter:PlaySound("dontstarve_DLC001/creatures/bearger/swhoosh") end),
  178. TimeEvent(20*FRAMES, function(inst)
  179. ShakeIfClose(inst)
  180. inst.components.groundpounder:GroundPound()
  181. inst.cangroundpound = false
  182. attacks_til_groundpound = 4
  183. inst.SoundEmitter:PlaySound("dontstarve_DLC001/creatures/bearger/groundpound")
  184. end),
  185. },
  186.  
  187. events=
  188. {
  189. EventHandler("animover", function(inst)
  190. inst.AnimState:PlayAnimation("idle")
  191. inst.sg:GoToState("idle")
  192. end),
  193. },
  194. },
  195. State {
  196. name = "chop",
  197. tags = {"chopping"},
  198. onenter = function(inst)
  199. inst.Physics:Stop()
  200. inst.AnimState:PlayAnimation("atk")
  201. inst.components.combat:StartAttack()
  202. print ("chopped once!")
  203. end,
  204. timeline = {
  205. TimeEvent(13*FRAMES, function(inst)
  206. inst:PerformBufferedAction()
  207. end),
  208. },
  209. events = {
  210. EventHandler("animover", function(inst)
  211. inst.sg:GoToState("idle")
  212. end),
  213. },
  214. },
  215. State {
  216. name = "eat",
  217. tags = {"busy"},
  218. onenter = function(inst)
  219. inst.Physics:Stop()
  220. inst.AnimState:PlayAnimation("eat")
  221. end,
  222. events = {
  223. EventHandler("animover", function(inst)
  224. inst.sg:GoToState("idle")
  225. end),
  226. },
  227. },
  228. State {
  229. name = "hit",
  230. tags = {"busy"},
  231. onenter = function(inst)
  232. inst:InterruptBufferedAction()
  233. inst.SoundEmitter:PlaySound("dontstarve/wilson/hit")
  234. inst.AnimState:PlayAnimation("hit")
  235. inst.Physics:Stop()
  236. end,
  237. events = {
  238. EventHandler("animover", function(inst)
  239. inst.sg:GoToState("idle")
  240. end),
  241. },
  242. timeline = {
  243. TimeEvent(3*FRAMES, function(inst)
  244. inst.sg:RemoveStateTag("busy")
  245. end),
  246. },
  247. }
  248. }
  249.  
  250. CommonStates.AddWalkStates(states, {
  251. walktimeline = {
  252. TimeEvent(0*FRAMES, PlayFootstep),
  253. TimeEvent(12*FRAMES, PlayFootstep),
  254. },
  255. })
  256.  
  257. CommonStates.AddRunStates(states, {
  258. runtimeline = {
  259. TimeEvent(0*FRAMES, PlayFootstep),
  260. TimeEvent(10*FRAMES, PlayFootstep),
  261. },
  262. })
  263.  
  264. CommonStates.AddSimpleState(states, "refuse", {"busy"})
  265.  
  266. --CommonStates.AddIdle(states,"idle2")
  267. --CommonStates.AddSimpleState(states,"hit", "hit", {"busy"})
  268. --CommonStates.AddFrozenStates(states)
  269. --CommonStates.AddSimpleActionState(states,"pickup", "pig_pickup", 10*FRAMES, {"busy"})
  270. --CommonStates.AddSimpleActionState(states, "gohome", "pig_pickup", 4*FRAMES, {"busy"})
  271.  
  272. return StateGraph("summonbeserker", states, events, "idle", actionhandlers)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement