Advertisement
Guest User

Untitled

a guest
May 25th, 2015
337
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.64 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("punch")
  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. if inst.components.locomotor then
  167. inst.components.locomotor:StopMoving()
  168. end
  169. inst.AnimState:PlayAnimation("punch")
  170. --end
  171. end,
  172.  
  173. timeline=
  174. {
  175. TimeEvent(17*FRAMES, function(inst) inst.SoundEmitter:PlaySound("dontstarve_DLC001/creatures/bearger/swhoosh") end),
  176. TimeEvent(20*FRAMES, function(inst)
  177. ShakeIfClose(inst)
  178. inst.components.groundpounder:GroundPound()
  179. inst.cangroundpound = false
  180. attacks_til_groundpound = 4
  181. inst.SoundEmitter:PlaySound("dontstarve_DLC001/creatures/bearger/groundpound")
  182. end),
  183. },
  184.  
  185. events=
  186. {
  187. EventHandler("animover", function(inst)
  188. inst.AnimState:PlayAnimation("idle")
  189. inst.sg:GoToState("idle")
  190. end),
  191. },
  192. },
  193. State {
  194. name = "chop",
  195. tags = {"chopping"},
  196. onenter = function(inst)
  197. inst.Physics:Stop()
  198. inst.AnimState:PlayAnimation("atk")
  199. inst.components.combat:StartAttack()
  200. print ("chopped once!")
  201. end,
  202. timeline = {
  203. TimeEvent(13*FRAMES, function(inst)
  204. inst:PerformBufferedAction()
  205. end),
  206. },
  207. events = {
  208. EventHandler("animover", function(inst)
  209. inst.sg:GoToState("idle")
  210. end),
  211. },
  212. },
  213. State {
  214. name = "eat",
  215. tags = {"busy"},
  216. onenter = function(inst)
  217. inst.Physics:Stop()
  218. inst.AnimState:PlayAnimation("eat")
  219. end,
  220. events = {
  221. EventHandler("animover", function(inst)
  222. inst.sg:GoToState("idle")
  223. end),
  224. },
  225. },
  226. State {
  227. name = "hit",
  228. tags = {"busy"},
  229. onenter = function(inst)
  230. inst:InterruptBufferedAction()
  231. inst.SoundEmitter:PlaySound("dontstarve/wilson/hit")
  232. inst.AnimState:PlayAnimation("hit")
  233. inst.Physics:Stop()
  234. end,
  235. events = {
  236. EventHandler("animover", function(inst)
  237. inst.sg:GoToState("idle")
  238. end),
  239. },
  240. timeline = {
  241. TimeEvent(3*FRAMES, function(inst)
  242. inst.sg:RemoveStateTag("busy")
  243. end),
  244. },
  245. }
  246. }
  247.  
  248. CommonStates.AddWalkStates(states, {
  249. walktimeline = {
  250. TimeEvent(0*FRAMES, PlayFootstep),
  251. TimeEvent(12*FRAMES, PlayFootstep),
  252. },
  253. })
  254.  
  255. CommonStates.AddRunStates(states, {
  256. runtimeline = {
  257. TimeEvent(0*FRAMES, PlayFootstep),
  258. TimeEvent(10*FRAMES, PlayFootstep),
  259. },
  260. })
  261.  
  262. CommonStates.AddSimpleState(states, "refuse", {"busy"})
  263.  
  264. --CommonStates.AddIdle(states,"idle2")
  265. --CommonStates.AddSimpleState(states,"hit", "hit", {"busy"})
  266. --CommonStates.AddFrozenStates(states)
  267. --CommonStates.AddSimpleActionState(states,"pickup", "pig_pickup", 10*FRAMES, {"busy"})
  268. --CommonStates.AddSimpleActionState(states, "gohome", "pig_pickup", 4*FRAMES, {"busy"})
  269.  
  270. return StateGraph("summonbeserker", states, events, "idle", actionhandlers)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement