More work on cities

Fixed some bugs, more work on city management terminal
This commit is contained in:
Light2
2014-06-13 03:41:07 +02:00
parent eb83dde930
commit 6eea20bf36
10 changed files with 505 additions and 184 deletions
@@ -1,64 +1,79 @@
from resources.common import RadialOptions
from resources.common import OutOfBand
from protocol.swg import ResourceListForSurveyMessage
from services.sui.SUIService import MessageBoxType
from services.sui.SUIWindow import Trigger
from java.util import Vector
from java.lang import System
import main.NGECore
import sys
def createRadial(core, owner, target, radials):
#(byte parentId, short optionId, byte optionType, String description)
radials.clear()
city = core.playerCityService.getCityObjectIsIn(owner)
if not city:
return
radials.add(RadialOptions(0, 7, 0, 'Examine'))
radials.add(RadialOptions(0, 216, 0, '@city/city:city_management'))
radials.add(RadialOptions(0, 226, 0, '@city/city:city_info'))
radials.add(RadialOptions(0, 227, 0, '@city/city:remove_trainers'))
radials.add(RadialOptions(2, 217, 0, '@city/city:city_name_new_t'))
radials.add(RadialOptions(2, 222, 0, '@city/city:city_register'))
radials.add(RadialOptions(2, 224, 0, '@city/city:unzone'))
radials.add(RadialOptions(2, 218, 0, '@city/city:city_militia'))
radials.add(RadialOptions(2, 219, 0, '@city/city:treasury_taxes'))
radials.add(RadialOptions(2, 221, 0, '@city/city:treasury_withdraw'))
radials.add(RadialOptions(2, 225, 0, '@city/city:city_specializations'))
radials.add(RadialOptions(2, 228, 0, '@city/city:align'))
radials.add(RadialOptions(3, 121, 0, '@city/city:non_citizen_city_status'))
radials.add(RadialOptions(3, 122, 0, '@city/city:rank_info_t'))
radials.add(RadialOptions(3, 123, 0, '@city/city:citizen_list_t'))
radials.add(RadialOptions(3, 230, 0, '@city/city:revoke_citizenship'))
radials.add(RadialOptions(0, 211, 0, '@city/city:city_info'))
if city.getMayorID() == owner.getObjectID():
radials.add(RadialOptions(0, 216, 0, '@city/city:city_management'))
radials.add(RadialOptions(3, 231, 0, 'Add 10 citizens'))
radials.add(RadialOptions(3, 232, 0, 'Deduct 10 citizens'))
radials.add(RadialOptions(2, 212, 0, '@city/city:city_status'))
radials.add(RadialOptions(2, 213, 0, '@city/city:citizen_list_t'))
radials.add(RadialOptions(2, 214, 0, '@city/city:city_structures'))
radials.add(RadialOptions(2, 223, 0, '@city/city:rank_info_t'))
radials.add(RadialOptions(2, 224, 0, '@city/city:city_maint'))
radials.add(RadialOptions(2, 215, 0, '@city/city:treasury_status'))
radials.add(RadialOptions(2, 220, 0, '@city/city:treasury_deposit'))
if owner.getPlayerObject().getCitizenship() != 3 and core.playerCityService.getPlayerCity(owner) == city:
radials.add(RadialOptions(2, 230, 0, '@city/city:revoke_citizenship'))
if owner.getClient().isGM():
radials.add(RadialOptions(2, 231, 0, 'Add 10 citizens'))
radials.add(RadialOptions(2, 232, 0, 'Deduct 10 citizens'))
if city.getMayorID() != owner.getObjectID():
print 'here'
return
radials.add(RadialOptions(0, 216, 0, '@city/city:city_management'))
#radials.add(RadialOptions(0, 227, 0, '@city/city:remove_trainers')) not needed for pswg
radials.add(RadialOptions(3, 217, 0, '@city/city:city_name_new_t'))
if city.isRegistered():
radials.add(RadialOptions(3, 222, 0, '@city/city:city_unregister'))
else:
radials.add(RadialOptions(3, 222, 0, '@city/city:city_register'))
if city.isZoningEnabled():
radials.add(RadialOptions(3, 226, 0, '@city/city:unzone'))
else:
radials.add(RadialOptions(3, 226, 0, '@city/city:zone'))
radials.add(RadialOptions(3, 218, 0, '@city/city:city_militia'))
radials.add(RadialOptions(3, 219, 0, '@city/city:treasury_taxes'))
radials.add(RadialOptions(3, 221, 0, '@city/city:treasury_withdraw'))
radials.add(RadialOptions(3, 225, 0, '@city/city:city_specializations'))
radials.add(RadialOptions(3, 228, 0, '@city/city:align'))
return
def handleSelection(core, owner, target, option):
playerCity = core.playerCityService.getPlayerCity(owner)
if playerCity==None:
playerCity = core.playerCityService.getCityObjectIsIn(owner)
if playerCity == None:
return
if option == 217:
if owner is not None:
handleSetCityName(core, owner, target, option)
return
if option == 124:
if owner is not None:
core.housingService.createStatusSUIPage(owner,target)
return
if option == 129:
if owner is not None:
core.housingService.createPayMaintenanceSUIPage(owner,target)
return
if option == 50:
if owner is not None:
core.housingService.createRenameSUIPage(owner,target)
return
if option == 222:
if owner is not None:
handleRegisterMap(core, owner, target, option)
return
if option == 171:
if owner is not None:
core.housingService.handleListAllItems(owner,target)
if playerCity.getMayorID() == owner.getObjectID():
if playerCity.isRegistered():
handleUnregisterMap(core, owner, target, option)
else:
handleRegisterMap(core, owner, target, option)
return
if option == 219:
if owner is not None:
@@ -72,45 +87,134 @@ def handleSelection(core, owner, target, option):
if owner is not None:
handleWithdrawal(core, owner, target, option)
return
if option == 121:
if option == 212:
if owner is not None:
handleCityInfo(core, owner, target, option)
return
if option == 223:
if owner is not None:
handleCityRankInfo(core, owner, target, option)
return
if option == 122:
if owner is not None:
handleCityRankInfo(core, owner, target, option)
return
if option == 123:
if option == 213:
if owner is not None:
handleCitizenList(core, owner, target, option)
return
if option == 231:
if owner is not None:
handle10Add(core, owner, target, option)
return
if option == 232:
if owner is not None:
handle10Deduct(core, owner, target, option)
return
if option == 220:
if owner is not None:
handleDeposit(core, owner, target, option)
return
if option == 226:
if owner is not None:
handleToggleZoning(core, owner, target, option)
return
def handleDeposit(core, owner, target, option):
playerCity = core.playerCityService.getPlayerCity(owner)
suiSvc = core.suiService
suiWindow = suiSvc.createSUIWindow('Script.transfer', owner, target, 10)
suiWindow.setProperty('transaction.txtInputFrom:Text', '@city/city:total_funds')
suiWindow.setProperty('bg.caption.lblTitle:Text', '@city/city:treasury_deposit')
suiWindow.setProperty('Prompt.lblPrompt:Text', '@city/city:treasury_deposit_d')
suiWindow.setProperty('transaction.lblFrom:Text', '@city/city:total_funds')
suiWindow.setProperty('transaction.lblTo:Text', '@city/city:treasury')
suiWindow.setProperty('transaction.lblStartingFrom:Text', str(owner.getCashCredits()))
suiWindow.setProperty('transaction.lblStartingTo:Text', '')
suiWindow.setProperty('transaction.txtInputFrom:Text', str(owner.getCashCredits()))
suiWindow.setProperty('transaction.txtInputTo:Text', '')
suiWindow.setProperty('transaction:ConversionRatioFrom', '1')
suiWindow.setProperty('transaction:ConversionRatioTo', '1')
returnParams = Vector()
returnParams.add('transaction.txtInputFrom:Text')
returnParams.add('transaction.txtInputTo:Text')
suiWindow.addHandler(0, '', Trigger.TRIGGER_OK, returnParams, handleDepositSUI)
suiSvc.openSUIWindow(suiWindow)
return
def handleDepositSUI(owner, window, eventType, returnList):
playerCity = main.NGECore.getInstance().playerCityService.getPlayerCity(owner)
if not playerCity:
return
amount = int(returnList.get(0))
cash = owner.getCashCredits()
deposit = cash - amount
if amount > cash or deposit < 1:
owner.sendSystemMessage('@city/city:positive_deposit', 0)
return
if playerCity.getCityTreasury() + deposit > 100000000:
owner.sendSystemMessage('@city/city:positive_deposit', 0)
return
playerCity.addToTreasury(deposit)
owner.deductCashCredits(deposit)
owner.sendSystemMessage(OutOfBand.ProsePackage('@city/city:deposit_treasury', deposit), 0)
return
def handleToggleZoning(core, owner, target, option):
playerCity = main.NGECore.getInstance().playerCityService.getPlayerCity(owner)
if not playerCity or playerCity.getMayorID() != owner.getObjectID():
return
playerCity.setZoningEnabled(!playerCity.isZoningEnabled())
if playerCity.isZoningEnabled():
owner.sendSystemMessage('@city/city:zoning_enabled', 0)
else:
owner.sendSystemMessage('@city/city:zoning_disabled', 0)
return
def handle10Add(core, owner, target, option):
playerCity = main.NGECore.getInstance().playerCityService.getPlayerCity(owner)
playerCity.Add10MoreCitizens()
return
def handle10Deduct(core, owner, target, option):
playerCity = main.NGECore.getInstance().playerCityService.getPlayerCity(owner)
playerCity.Deduct10Citizens()
return
def setnameCallBack(owner, window, eventType, returnList):
def handleSetCityName(core, owner, target, option):
playerCity = main.NGECore.getInstance().playerCityService.getPlayerCity(owner)
if not playerCity:
return
if playerCity.getCityNameChangeCooldown() > System.currentTimeMillis():
owner.sendSystemMessage('You may only change the city name once in 4 weeks.', 0)
return
window = core.suiService.createInputBox(2, '@city/city:city_name_new_t','@city/city:city_name_new_d', owner, None, 0)
window.setProperty('txtInput:MaxLength', '40')
returnList = Vector()
returnList.add('txtInput:LocalText')
window.addHandler(0, '', Trigger.TRIGGER_OK, returnList, setNameCallBack)
return
def setNameCallBack(owner, window, eventType, returnList):
if returnList.size()==0:
return
name = returnList.get(0)
if not core.characterService.checkName(name, owner.getClient(), True):
owner.sendSystemMessage('@player_structure:not_valid_name', 0)
return
if not core.playerCityService.doesCityNameExist(name):
owner.sendSystemMessage('@player_structure:cityname_not_unique', 0)
return
playerCity = main.NGECore.getInstance().playerCityService.getPlayerCity(owner)
playerCity.setCityName(returnList.get(0))
playerCity.setCityName(name)
playerCity.setCityNameChangeCooldown(System.currentTimeMillis() + str(604800 * 4 * 1000))
# TODO send mail
owner.sendSystemMessage('@city/city:name_changed', 0)
return
@@ -118,7 +222,7 @@ def setnameCallBack(owner, window, eventType, returnList):
def handleAdjustTaxes(core, owner, target, option):
playerCity = main.NGECore.getInstance().playerCityService.getPlayerCity(owner)
if playerCity.getRank()<2:
if playerCity.getRank() < 2:
owner.sendSystemMessage('@city/city:no_rank_taxes', 0)
return
@@ -284,54 +388,16 @@ def handleSetGarageTaxCallBack(owner, window, eventType, returnList):
def handleWithdrawal(core, owner, target, option):
playerCity = main.NGECore.getInstance().playerCityService.getPlayerCity(owner)
window = core.suiService.createSUIWindow("Script.transfer", owner, target, 10)
window.setProperty("bg.caption.lblTitle:Text", "@city/city:treasury_withdraw_subject")
window.setProperty("Prompt.lblPrompt:Text", "@city/city:treasury_withdraw_prompt" + "\n \n @city/city:treasury_status : %s" % playerCity.getCityTreasury())
window.setProperty("msgPayMaintenance", "transaction.txtInputFrom");
window.setProperty("transaction.lblFrom:Text", "@city/city:treasury_balance_t");
window.setProperty("transaction.lblTo:Text", "@city/city:treasury_withdraw");
window.setProperty("transaction.lblFrom", "@city/city:treasury_balance_t");
window.setProperty("transaction.lblTo", "@city/city:treasury_withdraw");
window.setProperty("transaction.lblStartingFrom:Text", '%s' % playerCity.getCityTreasury());
window.setProperty("transaction.lblStartingTo:Text", '0');
window.setProperty("transaction:InputFrom", "555555");
window.setProperty("transaction:InputTo", "666666");
window.setProperty("transaction:txtInputFrom", '%s' % playerCity.getCityTreasury());
window.setProperty("transaction:txtInputTo", "1");
window.setProperty("transaction.txtInputFrom:Text", '%s' % playerCity.getCityTreasury());
window.setProperty("transaction.txtInputTo:Text", "" + "0");
window.setProperty("transaction.ConversionRatioFrom", "1");
window.setProperty("transaction.ConversionRatioTo", "0");
window.setProperty("btnOk:visible", "True");
window.setProperty("btnCancel:visible", "True");
window.setProperty("btnOk:Text", "@ok");
window.setProperty("btnCancel:Text", "@cancel");
returnList = Vector()
returnList.add('transaction.txtInputFrom:Text')
returnList.add('ransaction.txtInputTo:Text')
window.addHandler(0, '', Trigger.TRIGGER_OK, returnList, setWithdrawalCallBack)
window.addHandler(1, '', Trigger.TRIGGER_CANCEL, returnList, setWithdrawalCallBack)
core.suiService.openSUIWindow(window);
return
def setWithdrawalCallBack(owner, window, eventType, returnList):
if returnList.size()==0:
if not playerCity:
return
playerCity = main.NGECore.getInstance().playerCityService.getPlayerCity(owner)
playerCity.setCityName(returnList.get(0))
owner.sendSystemMessage('@city/city:name_changed', 0)
return
if playerCity.getCityTreasuryWithdrawalCooldown() > System.currentTimeMillis():
owner.sendSystemMessage('@city/city:withdraw_daily', 0)
return
core.playerCityService.handleCityTreasuryWithdrawal(owner)
def handleCitizenList(core, owner, target, option):
def handleCitizenList(core, owner, target, option):
# wasnt there a new list layout in NGE ?
window = core.suiService.createSUIWindow('Script.listBox', owner, target, 0);
window.setProperty('bg.caption.lblTitle:Text', '@city/city:citizen_list_t')
window.setProperty('Prompt.lblPrompt:Text', '@city/city:citizen_list_prompt')
@@ -340,7 +406,12 @@ def handleCitizenList(core, owner, target, option):
index = 1;
for citizen in playerCity.getCitizens():
citizenObject = core.objectService.getObject(citizen)
window.addListBoxMenuItem(citizenObject.getCustomName(),index)
if not citizenObject:
continue
name = citizenObject.getCustomName()
if citizenObject.getPlayerObject().getCitizenship() == 2:
name += ' (Militia)'
window.addListBoxMenuItem(name,index)
index += 1
window.setProperty('btnOk:visible', 'True')
@@ -351,35 +422,43 @@ def handleCitizenList(core, owner, target, option):
returnList = Vector()
returnList.add('txtInput:LocalText')
window.addHandler(0, '', Trigger.TRIGGER_OK, returnList, setCitizenListCallBack)
window.addHandler(1, '', Trigger.TRIGGER_CANCEL, returnList, setCitizenListCallBack)
core.suiService.openSUIWindow(window);
return
def setCitizenListCallBack(owner, window, eventType, returnList):
#handle waypoint creation to citizen's house
idx = returnList.get(0)
# todo add waypoint
return
def handleCityRankInfo(core, owner, target, option):
window = core.suiService.createSUIWindow('Script.listBox', owner, target, 0);
window.setProperty('bg.caption.lblTitle:Text', '@city/city:rank_info_t')
window.setProperty('Prompt.lblPrompt:Text', '@city/city:rank_info_d')
def handleCityInfo(core, owner, target, option):
window = core.suiService.createSUIWindow('Script.listBox', owner, None, 0);
window.setProperty('bg.caption.lblTitle:Text', '@city/city:city_info_t')
window.setProperty('Prompt.lblPrompt:Text', '@city/city:city_info_d')
playerCity = main.NGECore.getInstance().playerCityService.getPlayerCity(owner)
window.addListBoxMenuItem('City : ' + playerCity.getCityName(),0)
window.addListBoxMenuItem('@city/city:radius_prompt : %s' % playerCity.getCityRadius(),1)
window.addListBoxMenuItem('@city/city:city_rank_prompt : @city/city:rank' + str(playerCity.getRank()),2)
window.addListBoxMenuItem('@city/city:reg_citizen_prompt : %s' % len(playerCity.getCitizens()),3)
if playerCity.getRank()>=3 and playerCity.getSpecialization()>-1:
mayor = core.objectService.getObject(playerCity.getMayorID())
if not mayor:
mayor = core.objectService.getCreatureFromDB(playerCity.getMayorID())
window.addListBoxMenuItem('@city/city:name_prompt : ' + playerCity.getCityName(),0)
if mayor:
window.addListBoxMenuItem('@city/city:mayor_prompt : ' + mayor.getCustomName(),5)
window.addListBoxMenuItem('@city/city:location_prompt : ' + str(playerCity.getCityCenterPosition().x) + ' ' + str(playerCity.getCityCenterPosition().z),6)
window.addListBoxMenuItem('@city/city:radius_prompt : %s' % playerCity.getCityRadius(),1)
window.addListBoxMenuItem('@city/city:reg_citizen_prompt : %s' % len(playerCity.getCitizens()),7)
window.addListBoxMenuItem('@kb/kb_player_cities_n:civic_structures_n : %s' % playerCity.getCivicStructuresCount(),8)
window.addListBoxMenuItem('@city/city:decorations : %s' % 0,9) # todo when decorations are implemented
if playerCity.getRank() >= 3 and playerCity.getSpecialization() > -1:
window.addListBoxMenuItem('@city/city:specialization_prompt : @city/city:' + playerCity.getSpecializationSTFNamesAsList().get(playerCity.getSpecialization()),4)
window.addListBoxMenuItem('@city/city:city_rank_prompt : @city/city:rank' + str(playerCity.getRank()),2)
# TODO add tax info
window.setProperty('btnOk:visible', 'True')
window.setProperty('btnCancel:visible', 'True')
window.setProperty('btnOk:Text', '@ok')
window.setProperty('btnCancel:Text', '@cancel')
window.setProperty('btnCancel:Text', '@cancel')
playerCity = main.NGECore.getInstance().playerCityService.getPlayerCity(owner)
returnList = Vector()
returnList.add('txtInput:LocalText')
window.addHandler(0, '', Trigger.TRIGGER_OK, returnList, setCityInfoCallBack)
@@ -391,6 +470,29 @@ def setCityInfoCallBack(owner, window, eventType, returnList):
#handle waypoint creation to citizen's house
return
def handleCityRankInfo(core, owner, target, option):
window = core.suiService.createSUIWindow('Script.listBox', owner, None, 0);
window.setProperty('bg.caption.lblTitle:Text', '@city/city:rank_info_t')
window.setProperty('Prompt.lblPrompt:Text', '@city/city:rank_info_d')
playerCity = main.NGECore.getInstance().playerCityService.getPlayerCity(owner)
rank = playerCity.getRank()
nextRank = rank + 1
if nextRank > 5:
nextRank = 5
window.addListBoxMenuItem('@city/city:city_rank_prompt : @city/city:rank' + str(playerCity.getRank()),1)
window.addListBoxMenuItem('@city/city:reg_citizen_prompt : %s' % len(playerCity.getCitizens()),2)
window.addListBoxMenuItem('@city/city:pop_req_current_rank : ' + str(playerCity.getReqCitizenCountForRank(rank)),3)
window.addListBoxMenuItem('@city/city:pop_req_next_rank : ' + str(playerCity.getReqCitizenCountForRank(nextRank)),4)
window.setProperty('btnOk:visible', 'True')
window.setProperty('btnCancel:visible', 'True')
window.setProperty('btnOk:Text', '@ok')
window.setProperty('btnCancel:Text', '@cancel')
window.setProperty('btnCancel:Text', '@cancel')
core.suiService.openSUIWindow(window);
return
def handleRegisterMap(core, owner, target, option):
playerCity = main.NGECore.getInstance().playerCityService.getPlayerCity(owner)
@@ -401,11 +503,31 @@ def handleRegisterMap(core, owner, target, option):
if owner.getObjectId()!=playerCity.getMayorID():
owner.sendSystemMessage('@city/city:cant_register', 0)
return
if playerCity.isRegistered():
return
# now register it somehow
core.mapService.addLocation(owner.getPlanet(), playerCity.getCityName(), playerCity.getCityCenterPosition().x, playerCity.getCityCenterPosition().z, 17, 0, 0)
return
def handleUnregisterMap(core, owner, target, option):
playerCity = main.NGECore.getInstance().playerCityService.getPlayerCity(owner)
if playerCity.getRank()<3:
owner.sendSystemMessage('@city/city:cant_register_rank', 0)
return
if owner.getObjectId()!=playerCity.getMayorID():
owner.sendSystemMessage('@city/city:cant_register', 0)
return
if not playerCity.isRegistered():
return
core.mapService.removeLocation(owner.getPlanet(), playerCity.getCityCenterPosition().x, playerCity.getCityCenterPosition().z, 17)
return
def setRegisterMapCallBack(owner, window, eventType, returnList):
if returnList.size()==0:
return
@@ -417,7 +539,7 @@ def setRegisterMapCallBack(owner, window, eventType, returnList):
def handleSpecialization(core, owner, target, option):
playerCity = main.NGECore.getInstance().playerCityService.getPlayerCity(owner)
if playerCity.getRank()<3:
if playerCity.getRank() < 3:
owner.sendSystemMessage('@city/city:no_rank_spec', 0)
return
@@ -434,9 +556,6 @@ def handleSpecialization(core, owner, target, option):
window.addListBoxMenuItem('@city/city:city_spec_doctor',6)
window.addListBoxMenuItem('@city/city:city_spec_research',7)
window.addListBoxMenuItem('@city/city:city_spec_sample_rich',8)
window.addListBoxMenuItem('@city/city:city_spec_master_manufacturing',9)
window.addListBoxMenuItem('@city/city:city_spec_master_healing',10)
window.addListBoxMenuItem('@city/city:city_spec_stronghold',11)
window.setProperty('btnOk:visible', 'True')
window.setProperty('btnCancel:visible', 'True')