-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAI.hs
30 lines (22 loc) · 1009 Bytes
/
AI.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
module AI where
import Prelude hiding(Either(..))
import Data.List
import Data.Maybe
import Types.World
import Types.Common
performAI :: Entity -> World -> World
performAI monster world = selectBehavior behaviorStack world monster
where
behaviorStack = mBehaviorStack monster
selectBehavior :: [World -> Entity -> Maybe World] -> World -> Entity -> World
selectBehavior [] w m = error "No behaviors found in a monster's behaviorstack. To fix, ensure wait is at the end of every behaviorstack."
selectBehavior (f:fs) w m =
fromMaybe (selectBehavior fs w m) (f w m)
bossAI :: [Entity] -> World -> World
bossAI skippedEntities world
| eNextMove b == 0 =
world { wBoss = b {eNextMove = eSpeed b, eCurrPos = (1 + fst (eCurrPos b), snd $ eCurrPos b), eOldPos = eCurrPos b, bRivalKills = bRivalKills b + length skippedEntities } }
| otherwise =
world { wBoss = b { bRivalKills = bRivalKills b + length skippedEntities } }
where
b = wBoss world