@@ -104,10 +104,10 @@ export const ACTION_DEFINITIONS: Record<schema.Action, typeof Action<ActionUnion
104104 // chomping animation
105105 const src = match . currentRound . bodies . getById ( this . robotId ) // cat
106106 // const target = match.currentRound.bodies.getById(this.actionData.id()) // rat being eaten
107- const coords = renderUtils . getRenderCoords ( src . pos . x , src . pos . y , match . map . dimension , true )
108- const random1 = ( ( src . pos . x * 491 + src . pos . y * 603 + match . currentRound . roundNumber * 343 ) / 100 ) % 1 // https://xkcd.com/221/
109- const random2 = ( ( src . pos . x * 259 + src . pos . y * 429 + match . currentRound . roundNumber * 224 ) / 100 ) % 1
110- const interpolationFactor = match . getInterpolationFactor ( )
107+ // const coords = renderUtils.getRenderCoords(src.pos.x, src.pos.y, match.map.dimension, true)
108+ // const random1 = ((src.pos.x * 491 + src.pos.y * 603 + match.currentRound.roundNumber * 343) / 100) % 1 // https://xkcd.com/221/
109+ // const random2 = ((src.pos.x * 259 + src.pos.y * 429 + match.currentRound.roundNumber * 224) / 100) % 1
110+ // const interpolationFactor = match.getInterpolationFactor()
111111
112112 // ctx.save()
113113 // ctx.globalAlpha = 0.5 - 0.5 * interpolationFactor * interpolationFactor
@@ -133,6 +133,8 @@ export const ACTION_DEFINITIONS: Record<schema.Action, typeof Action<ActionUnion
133133 const srcBody = match . currentRound . bodies . getById ( this . robotId )
134134 const dstBody = match . currentRound . bodies . getById ( this . actionData . id ( ) )
135135
136+ if ( ! dstBody ) return
137+
136138 const from = srcBody . getInterpolatedCoords ( match )
137139 const to = dstBody . getInterpolatedCoords ( match )
138140
@@ -192,8 +194,11 @@ export const ACTION_DEFINITIONS: Record<schema.Action, typeof Action<ActionUnion
192194
193195 if ( target . beingCarried ) {
194196 // drop the target
195- const carrier = round . bodies . getById ( target . carrierRobot ! )
196- carrier . carriedRobot = undefined
197+ // const carrier = round.bodies.getById(target.carrierRobot!)
198+ if ( target . carrierRobot !== undefined ) {
199+ const carrier = round . bodies . getById ( target . carrierRobot )
200+ carrier . carriedRobot = undefined
201+ }
197202 target . size = 1
198203 target . beingCarried = false
199204 target . carrierRobot = undefined
@@ -358,6 +363,8 @@ export const ACTION_DEFINITIONS: Record<schema.Action, typeof Action<ActionUnion
358363 const srcBody = match . currentRound . bodies . getById ( this . robotId )
359364 const targetBody = match . currentRound . bodies . getById ( this . actionData . id ( ) )
360365
366+ if ( ! targetBody ) return
367+
361368 const from = srcBody . getInterpolatedCoords ( match )
362369 const to = targetBody . getInterpolatedCoords ( match )
363370
@@ -562,26 +569,27 @@ export const ACTION_DEFINITIONS: Record<schema.Action, typeof Action<ActionUnion
562569 [ schema . Action . ThrowRat ] : class ThrowRatAction extends Action < schema . ThrowRat > {
563570 apply ( round : Round ) : void {
564571 // maybe move rat to target loc
565- const body = round . bodies . getById ( this . robotId )
572+ const body = round . bodies . getById ( this . actionData . id ( ) )
566573 const endLoc = round . map . indexToLocation ( this . actionData . loc ( ) )
567- if ( body . carriedRobot !== undefined ) {
568- const carrier = round . bodies . getById ( body . carriedRobot )
574+ if ( body . carrierRobot !== undefined && round . bodies . hasId ( body . carrierRobot ) ) {
575+ const carrier = round . bodies . getById ( body . carrierRobot )
569576 carrier . carriedRobot = undefined
570577 }
571578 body . carrierRobot = undefined
572579 body . beingCarried = false
573580 body . size = 1
574- body . pos = { ...endLoc }
581+ // body.pos = { ...endLoc }
575582 }
576583 draw ( match : Match , ctx : CanvasRenderingContext2D ) : void {
577- const body = match . currentRound . bodies . getById ( this . robotId )
584+ if ( ! match . currentRound . bodies . hasId ( this . actionData . id ( ) ) ) return
585+ const body = match . currentRound . bodies . getById ( this . actionData . id ( ) )
578586 const pos = body . getInterpolatedCoords ( match )
579587 const coords = renderUtils . getRenderCoords ( pos . x , pos . y , match . map . dimension , true )
580588 const interp = match . getInterpolationFactor ( )
581589
582590 const from = pos
583591 const to = match . currentRound . map . indexToLocation ( this . actionData . loc ( ) )
584- console . log ( 'throw from' , from , 'to' , to )
592+
585593 const dx = to . x - from . x
586594 const dy = to . y - from . y
587595 const mag = Math . hypot ( dx , dy )
@@ -698,6 +706,8 @@ export const ACTION_DEFINITIONS: Record<schema.Action, typeof Action<ActionUnion
698706 const src = round . bodies . getById ( this . robotId )
699707 const target = round . bodies . getById ( this . actionData . id ( ) )
700708
709+ if ( ! target ) return
710+
701711 const damage = this . actionData . damage ( )
702712 target . hp = Math . max ( target . hp - damage , 0 )
703713 }
0 commit comments