From 0c2f4b29a06938097bddc08397030f1192663d3d Mon Sep 17 00:00:00 2001 From: CharonInferar Date: Sat, 26 Apr 2014 01:18:18 +0200 Subject: [PATCH] Grant zoning added test with 2 player chars to increase population to 2 citizens after zoning and declare residence. --- scripts/commands/grantzoningrights.py | 40 ++++++++++ src/services/housing/HousingService.java | 77 +++++++++++++++---- src/services/playercities/PlayerCity.java | 22 +++++- .../playercities/PlayerCityService.java | 32 ++++++-- 4 files changed, 148 insertions(+), 23 deletions(-) create mode 100644 scripts/commands/grantzoningrights.py diff --git a/scripts/commands/grantzoningrights.py b/scripts/commands/grantzoningrights.py new file mode 100644 index 00000000..21cbbb8d --- /dev/null +++ b/scripts/commands/grantzoningrights.py @@ -0,0 +1,40 @@ +import sys +from java.lang import System +from resources.common import OutOfBand +from resources.common import ProsePackage +import main.NGECore + +def setup(): + return + +def run(core, actor, target, commandString): + + if target == None: + return + + #if !actor.hasSkill('Politician'): + #You must be a Politician to enable city zoning. + #actor.sendSystemMessage('@city/city:zoning_skill', 0) + #return + + thisCity = main.NGECore.getInstance().playerCityService.getCityObjectIsIn(actor) + + if thisCity == None: + #not_in_city_limits + actor.sendSystemMessage('@city/city:not_in_city_limits', 0) + return + + if thisCity.getMayorID()!=actor.getObjectID() and not thisCity.isMilitiaMember(actor.getObjectID()): + #You must be the mayor of the city or a member of the city militia to grant zoning rights. + actor.sendSystemMessage('@city/city:grant_rights_fail', 0) + actor.sendSystemMessage('thisCity.getMayorID() %s' % thisCity.getMayorID(), 0) + actor.sendSystemMessage('actor.getObjectID() %s' % actor.getObjectID(), 0) + return + + #You have granted %TO zoning rights for 24 hours. + actor.sendSystemMessage(OutOfBand.ProsePackage("@city/city:rights_granted_self", "TO", target.getCustomName()), 0) + target.setAttachment('Has24HZoningFor',thisCity.getCityID()) + target.setAttachment('Has24HZoningUntil',System.currentTimeMillis()+60*60*24) + target.sendSystemMessage(OutOfBand.ProsePackage("@city/city:rights_granted", "TO", thisCity.getCityName()), 0) + + return \ No newline at end of file diff --git a/src/services/housing/HousingService.java b/src/services/housing/HousingService.java index ff85019e..47fdaceb 100644 --- a/src/services/housing/HousingService.java +++ b/src/services/housing/HousingService.java @@ -22,6 +22,7 @@ package services.housing; import java.io.IOException; +import java.math.BigInteger; import java.nio.file.FileVisitResult; import java.nio.file.FileVisitor; import java.nio.file.Files; @@ -85,6 +86,10 @@ public class HousingService implements INetworkDispatch { HouseTemplate houseTemplate = housingTemplates.get(deed.getTemplate()); Player_House_Deed playerHourseDeed = (Player_House_Deed)core.objectService.getObject(deed.getObjectID()); int structureLotCost = houseTemplate.getLotCost(); + + if (deed.getTemplate().contains("cityhall")) + structureLotCost = 0; + String structureTemplate = houseTemplate.getBuildingTemplate(); if(!houseTemplate.canBePlacedOn(actor.getPlanet().getName())) @@ -112,10 +117,55 @@ public class HousingService implements INetworkDispatch { float positionY = core.terrainService.getHeight(actor.getPlanetId(), positionX, positionZ) + 2f; - // Create the building + boolean canBuild = true; + + // Check for city founders joining a new city + PlayerCity cityActorIsIn = core.playerCityService.getCityObjectIsIn(actor); + + if (cityActorIsIn != null){ + // Actor is inside the bounds of a city, so zoning must be checked + //actor.setAttachment("Has24HZoningFor",cityActorIsIn.getCityID()); // for testing + //actor.setAttachment("Has24HZoningUntil",System.currentTimeMillis()+1000000); // for testing + if (actor.getAttachment("Has24HZoningFor")==null || actor.getAttachment("Has24HZoningFor")==null) + return; + int cityActorHasZoning = (int)actor.getAttachment("Has24HZoningFor"); + BigInteger zoningUntilBI = (BigInteger) actor.getAttachment("Has24HZoningUntil"); + long zoningUntil = zoningUntilBI.longValue(); + if (cityActorHasZoning==cityActorIsIn.getCityID() && System.currentTimeMillis() returnList = new Vector(); + returnList.add("txtInput:LocalText"); + window.addHandler(0, "", Trigger.TRIGGER_OK, returnList, new SUICallback() { + @Override + public void process(SWGObject owner, int eventType, Vector returnList) { + if (returnList.size()==0) + return; + PlayerCity playerCity = main.NGECore.getInstance().playerCityService.getPlayerCity((CreatureObject) owner); + playerCity.setCityName(returnList.get(0)); + //owner.sendSystemMessage("@city/city:name_changed", 0); + core.suiService.closeSUIWindow(owner, 0); + newCitySUI2((CreatureObject) owner, playerCity); + } + }); + core.suiService.openSUIWindow(window); + } + + public void newCitySUI2(CreatureObject citizen, final PlayerCity newCity) { final SUIWindow window = core.suiService.createSUIWindow("Script.messageBox", citizen, citizen, 0); window.setProperty("bg.caption.lblTitle:Text", "@city/city:rank0"); window.setProperty("Prompt.lblPrompt:Text", "@city/city:new_city_body"); @@ -135,6 +156,7 @@ public class PlayerCityService implements INetworkDispatch { }); core.suiService.openSUIWindow(window); } + @Override public void insertOpcodes(Map arg0,