From b8731f741b082b0b88e4fe6c3ebda7813bd58678 Mon Sep 17 00:00:00 2001 From: Cekis Date: Tue, 12 Apr 2016 03:18:59 +0100 Subject: [PATCH] Added new NPC Spawner base file. --- .../base_newbie_npc_spawner.java | 109 ++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100755 sku.0/sys.server/compiled/game/script/creature_spawner/base_newbie_npc_spawner.java diff --git a/sku.0/sys.server/compiled/game/script/creature_spawner/base_newbie_npc_spawner.java b/sku.0/sys.server/compiled/game/script/creature_spawner/base_newbie_npc_spawner.java new file mode 100755 index 000000000..ebdb02cf7 --- /dev/null +++ b/sku.0/sys.server/compiled/game/script/creature_spawner/base_newbie_npc_spawner.java @@ -0,0 +1,109 @@ +package script.creature_spawner; + +import script.dictionary; +import script.library.*; +import script.location; +import script.obj_id; + +import java.util.Vector; + +public class base_newbie_npc_spawner extends script.base_script +{ + public int maxPop = 3; + public boolean newbie = false; + + public base_newbie_npc_spawner() + { + } + public int OnInitialize(obj_id self) throws InterruptedException + { + spawnCreatures(self); + if(newbie) LOG("NewbieSpawn", "Spawning Init: " + self); + return SCRIPT_CONTINUE; + } + public void spawnCreatures(obj_id self) throws InterruptedException + { + if(newbie) LOG("NewbieSpawn", "Spawning Anew: " + self); + String whatToSpawn = utils.getStringScriptVar(self, "creatureToSpawn"); + if (whatToSpawn == null) + { + whatToSpawn = pickCreature(); + utils.setScriptVar(self, "creatureToSpawn", whatToSpawn); + } + if (hasObjVar(self, "pop")) + { + maxPop = getIntObjVar(self, "pop"); + if (newbie && maxPop > 20) + { + CustomerServiceLog("SPAWNER_OVERLOAD", "MaxPop of Spawner " + self + " was greater than 20. It was " + maxPop + " in fact."); + } + } + int count = utils.getIntScriptVar(self, "count"); + location goodLoc; + obj_id spawned; + Vector myCreations; + Vector theList; + while (count < maxPop) + { + if(newbie) LOG("NewbieSpawn", "spawning #" + count); + goodLoc = pickLocation(); + if (goodLoc == null) + { + goodLoc = getLocation(self); + } + spawned = create.object(whatToSpawn, goodLoc); + attachScript(spawned, "creature_spawner.death_msg"); + setObjVar(spawned, "creater", self); + if (!utils.hasScriptVar(self, "myCreations")) + { + myCreations = new Vector(); + myCreations.setSize(0); + utils.addElement(myCreations, spawned); + utils.setScriptVar(self, "myCreations", myCreations); + } + else + { + theList = utils.getResizeableObjIdArrayScriptVar(self, "myCreations"); + if (theList.size() >= maxPop) + { + CustomerServiceLog("SPAWNER_OVERLOAD", "Tried to spawn something even though the list was full."); + return; + } + else + { + theList.add(spawned); + utils.setScriptVar(self, "myCreations", theList); + } + } + if (hasObjVar(self, "useCityWanderScript")) + { + attachScript(spawned, "city.city_wander"); + } + else + { + ai_lib.setDefaultCalmBehavior(spawned, ai_lib.BEHAVIOR_LOITER); + } + count++; + utils.setScriptVar(self, "count", count); + } + } + public String pickCreature() throws InterruptedException + { + // note: this method should be overridden in all child classes. probably should + // make an interface to enforce this. + return "flail_cutthroat"; + } + public location pickLocation() throws InterruptedException + { + location here = getLocation(getSelf()); + here.x = here.x + rand(-5, 5); + here.z = here.z + rand(-5, 5); + return locations.getGoodLocationAroundLocation(here, 1f, 1f, 1.5f, 1.5f); + } + public int creatureDied(obj_id self, dictionary params) throws InterruptedException + { + spawning.planetSpawnersCreatureDied(self, params.getObjId("deadGuy")); + spawnCreatures(self); + return SCRIPT_CONTINUE; + } +}