monsters now stay near their spawner when idle (probably)

This commit is contained in:
troido 2017-10-29 16:50:09 +01:00
parent b3d35ad629
commit 2c2aa878ee
4 changed files with 15 additions and 10 deletions

View File

@ -63,7 +63,6 @@ The idea is to make 3 different kind of areas:
- better code documentation
- testing
- make idle NPC's stay around spawn
- nondeterminism in combat and grow times
- only plant seeds in soil
- make farming more work
@ -74,7 +73,6 @@ The idea is to make 3 different kind of areas:
- better reaction on player death
- room unloading when there are no players
- better inventory selection
- messages in the client
- runtime-created rooms
- in-game chat
- world persistence
@ -84,6 +82,8 @@ The idea is to make 3 different kind of areas:
## DONE
- make idle NPC's stay around spawn
- messages in the client
- sort objects on ground on height
- follow player when room larger than terminal
- multiple actions per keypress

View File

@ -6,9 +6,11 @@ import random
class MonsterAi:
def __init__(self, viewDist, moveChance=1):
def __init__(self, viewDist, moveChance=1, home=None, homesickness=0.25):
self.moveChance = moveChance
self.viewDist = viewDist
self.home = home
self.homesickness = homesickness
def attach(self, obj, roomData):
@ -41,7 +43,10 @@ class MonsterAi:
self.move.move(pathfinding.stepTo(self.owner, closest))
else:
if random.random() < self.moveChance:
direction = random.choice(["north", "south", "east", "west"])
if (self.home and self.home.inRoom() and random.random() < self.homesickness):
direction = pathfinding.stepTo(self.owner, self.home)
else:
direction = random.choice(["north", "south", "east", "west"])
self.move.move(direction)
def remove(self):

View File

@ -7,7 +7,7 @@ class Spawner:
def __init__(self, objectType, amount=1, respawnDelay=1, objectArgs=[], objectKwargs={}):
self.objectType = objectType
self.amount = amount
self.respawnDelay = respawnDelay # currently ignored
self.respawnDelay = respawnDelay
self.spawned = set()
self.objectArgs = objectArgs
self.objectKwargs = objectKwargs
@ -27,7 +27,7 @@ class Spawner:
self.timeouts.add(to)
def spawn(self, to):
obj = gameobjects.makeEntity(self.objectType, self.roomData, *self.objectArgs, **self.objectKwargs)
obj = gameobjects.makeEntity(self.objectType, self.roomData, *self.objectArgs, home=self.owner, **self.objectKwargs)
obj.place(self.owner.getGround())
self.spawned.add(obj)
self.timeouts.remove(to)

View File

@ -76,22 +76,22 @@ def makeSpikeTrap():
return Entity(sprite="spikes", height=1, components={"fighter": Fighter(maxHealth=25, strength=25), "collision": Trap()})
entities["spiketrap"] = makeSpikeTrap
def makeGoblin():
def makeGoblin(home=None):
return Entity(sprite="goblin", height=1.2, components={
"move": Move(slowness=3),
"fighter": Fighter(maxHealth=25, strength=5, slowness=6),
"alignment": Alignment(faction.EVIL),
"controller": MonsterAi(viewDist=8, moveChance=0.01),
"controller": MonsterAi(viewDist=8, moveChance=0.01, home=home),
"loot": Loot([("seed", .5), ("seed", .1)])
})
entities["goblin"] = makeGoblin
def makeTroll():
def makeTroll(home=None):
return Entity(sprite="troll", height=1.8, components={
"move": Move(slowness=4),
"fighter": Fighter(maxHealth=125, strength=12, slowness=10),
"alignment": Alignment(faction.EVIL),
"controller": MonsterAi(viewDist=8, moveChance=0.01),
"controller": MonsterAi(viewDist=8, moveChance=0.01, home=home),
"loot": Loot([("stone", 1), ("stone", .3), ("pebble", .5), ("pebble", .5), ("pebble", .5)])
})
entities["troll"] = makeTroll