diff --git a/.gitignore b/.gitignore index ab30f143..f80b1387 100644 --- a/.gitignore +++ b/.gitignore @@ -60,8 +60,13 @@ odb/chatRooms/je.info.* odb/resourcehistory/je.info.* odb/resourceroots/je.info.* odb/resources/je.info.* -odb/auction/je.info.* +<<<<<<< HEAD +odb/auction/je.info.* +odb/swgobjects/je.info.* +======= +odb/auction/je.info.* odb/bounties/je.info.* +>>>>>>> 12ca3ae66170fcfe09d848a7eea529041b9af5ad # External tool builders .externalToolBuilders/ diff --git a/ngengine_public.jar b/ngengine_public.jar index a78a6cba..11248832 100644 Binary files a/ngengine_public.jar and b/ngengine_public.jar differ diff --git a/odb/swgobjects/placeholder.txt b/odb/swgobjects/placeholder.txt new file mode 100644 index 00000000..e69de29b 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/scripts/commands/setgodmode.py b/scripts/commands/setgodmode.py index 63019d92..b0e78d52 100644 --- a/scripts/commands/setgodmode.py +++ b/scripts/commands/setgodmode.py @@ -113,11 +113,8 @@ def run(core, actor, target, commandString): actor.removeAbility("admin") playerObject.setGodLevel(0) - elif command == 'setBounty' and arg1: - if not core.missionService.addToExistingBounty(actor, int(arg1)): - core.missionService.createNewBounty(actor, int(arg1)) - - actor.sendSystemMessage('Your bounty has been set to an additional ' + str(arg1) + ' credits.', 0) + elif command == 'setBounty': + core.playerService.sendSetBountyWindow(actor, actor) return return diff --git a/scripts/houses/player_garden_tatooine_sml_01.py b/scripts/houses/player_garden_tatooine_sml_01.py new file mode 100644 index 00000000..ed3b2981 --- /dev/null +++ b/scripts/houses/player_garden_tatooine_sml_01.py @@ -0,0 +1,15 @@ +import sys +from services.housing import HouseTemplate +from engine.resources.scene import Point3D + +def setup(housingTemplates): + houseTemplate = HouseTemplate("object/tangible/deed/city_deed/shared_garden_tatooine_sml_01_deed.iff", "object/building/player/city/shared_garden_tatooine_sml_01.iff", 0) + + houseTemplate.addBuildingSign("object/tangible/sign/player/shared_house_address.iff", Point3D(1, 2, 3)) + houseTemplate.addPlaceablePlanet("tatooine") + houseTemplate.addPlaceablePlanet("dantooine") + houseTemplate.addPlaceablePlanet("lok") + houseTemplate.setDefaultItemLimit(0) + + housingTemplates.put(houseTemplate.getDeedTemplate(), houseTemplate) + return \ No newline at end of file diff --git a/scripts/houses/player_shuttleport_tatooine.py b/scripts/houses/player_shuttleport_tatooine.py new file mode 100644 index 00000000..4d7e480f --- /dev/null +++ b/scripts/houses/player_shuttleport_tatooine.py @@ -0,0 +1,12 @@ +import sys +from services.housing import HouseTemplate +from engine.resources.scene import Point3D + +def setup(housingTemplates): + houseTemplate = HouseTemplate("object/tangible/deed/city_deed/shared_shuttleport_tatooine_deed.iff", "object/building/tatooine/shared_shuttleport_tatooine.iff", 1) + + houseTemplate.addBuildingSign("object/tangible/sign/player/shared_house_address.iff", Point3D(float(3.5),float(-0.3),float(3.5))) + houseTemplate.addPlaceablePlanet("tatooine") + houseTemplate.setDefaultItemLimit(0) + housingTemplates.put(houseTemplate.getDeedTemplate(), houseTemplate) + return \ No newline at end of file diff --git a/scripts/object/building/player/city/garden_tatooine_sml_01.py b/scripts/object/building/player/city/garden_tatooine_sml_01.py index ccad8904..287ca8f0 100644 --- a/scripts/object/building/player/city/garden_tatooine_sml_01.py +++ b/scripts/object/building/player/city/garden_tatooine_sml_01.py @@ -1,4 +1,14 @@ import sys +from engine.resources.scene import Point3D +from engine.resources.scene import Quaternion def setup(core, object): + sign = core.objectService.createChildObject(object, 'object/tangible/sign/player/shared_house_address.iff', -13.7, 3, 9.1, -1, 0, -1) + print(sign) + object.setAttachment("structureSign", sign) + + structureterminal = core.objectService.createChildObject(object, 'object/tangible/terminal/shared_terminal_player_structure.iff', -17.2, 1.5 , 8, 1, 0 ,4) + #structureterminal.setAttachment('radial_filename', 'structure_management_terminal') + structureterminal.setAttachment('housing_parentstruct', object) + return \ No newline at end of file diff --git a/scripts/object/mobile/dressed_imperial_officer_f.py b/scripts/object/mobile/dressed_imperial_officer_f.py index ccad8904..b9963b3e 100644 --- a/scripts/object/mobile/dressed_imperial_officer_f.py +++ b/scripts/object/mobile/dressed_imperial_officer_f.py @@ -1,4 +1,10 @@ import sys +from resources.datatables import Options def setup(core, object): - return \ No newline at end of file + object.setAttachment('radial_filename', 'object/conversation'); + object.setAttachment('conversationFile','imp_recruiter') + object.setOptionsBitmask(Options.CONVERSABLE | Options.INVULNERABLE) + object.setStfFilename('mob/creature_names') + object.setStfName('imperial_recruiter') + return diff --git a/scripts/object/mobile/dressed_imperial_officer_m_2.py b/scripts/object/mobile/dressed_imperial_officer_m_2.py index ccad8904..b9963b3e 100644 --- a/scripts/object/mobile/dressed_imperial_officer_m_2.py +++ b/scripts/object/mobile/dressed_imperial_officer_m_2.py @@ -1,4 +1,10 @@ import sys +from resources.datatables import Options def setup(core, object): - return \ No newline at end of file + object.setAttachment('radial_filename', 'object/conversation'); + object.setAttachment('conversationFile','imp_recruiter') + object.setOptionsBitmask(Options.CONVERSABLE | Options.INVULNERABLE) + object.setStfFilename('mob/creature_names') + object.setStfName('imperial_recruiter') + return diff --git a/scripts/object/mobile/dressed_imperial_officer_m_3.py b/scripts/object/mobile/dressed_imperial_officer_m_3.py index ccad8904..b9963b3e 100644 --- a/scripts/object/mobile/dressed_imperial_officer_m_3.py +++ b/scripts/object/mobile/dressed_imperial_officer_m_3.py @@ -1,4 +1,10 @@ import sys +from resources.datatables import Options def setup(core, object): - return \ No newline at end of file + object.setAttachment('radial_filename', 'object/conversation'); + object.setAttachment('conversationFile','imp_recruiter') + object.setOptionsBitmask(Options.CONVERSABLE | Options.INVULNERABLE) + object.setStfFilename('mob/creature_names') + object.setStfName('imperial_recruiter') + return diff --git a/scripts/object/mobile/dressed_imperial_officer_m_4.py b/scripts/object/mobile/dressed_imperial_officer_m_4.py index ccad8904..b9963b3e 100644 --- a/scripts/object/mobile/dressed_imperial_officer_m_4.py +++ b/scripts/object/mobile/dressed_imperial_officer_m_4.py @@ -1,4 +1,10 @@ import sys +from resources.datatables import Options def setup(core, object): - return \ No newline at end of file + object.setAttachment('radial_filename', 'object/conversation'); + object.setAttachment('conversationFile','imp_recruiter') + object.setOptionsBitmask(Options.CONVERSABLE | Options.INVULNERABLE) + object.setStfFilename('mob/creature_names') + object.setStfName('imperial_recruiter') + return diff --git a/scripts/object/mobile/dressed_imperial_officer_m_5.py b/scripts/object/mobile/dressed_imperial_officer_m_5.py index ccad8904..b9963b3e 100644 --- a/scripts/object/mobile/dressed_imperial_officer_m_5.py +++ b/scripts/object/mobile/dressed_imperial_officer_m_5.py @@ -1,4 +1,10 @@ import sys +from resources.datatables import Options def setup(core, object): - return \ No newline at end of file + object.setAttachment('radial_filename', 'object/conversation'); + object.setAttachment('conversationFile','imp_recruiter') + object.setOptionsBitmask(Options.CONVERSABLE | Options.INVULNERABLE) + object.setStfFilename('mob/creature_names') + object.setStfName('imperial_recruiter') + return diff --git a/scripts/object/mobile/dressed_imperial_officer_m_6.py b/scripts/object/mobile/dressed_imperial_officer_m_6.py index ccad8904..b9963b3e 100644 --- a/scripts/object/mobile/dressed_imperial_officer_m_6.py +++ b/scripts/object/mobile/dressed_imperial_officer_m_6.py @@ -1,4 +1,10 @@ import sys +from resources.datatables import Options def setup(core, object): - return \ No newline at end of file + object.setAttachment('radial_filename', 'object/conversation'); + object.setAttachment('conversationFile','imp_recruiter') + object.setOptionsBitmask(Options.CONVERSABLE | Options.INVULNERABLE) + object.setStfFilename('mob/creature_names') + object.setStfName('imperial_recruiter') + return diff --git a/scripts/object/mobile/dressed_rebel_recruiter_human_female_01.py b/scripts/object/mobile/dressed_rebel_recruiter_human_female_01.py index ccad8904..e0dd64a1 100644 --- a/scripts/object/mobile/dressed_rebel_recruiter_human_female_01.py +++ b/scripts/object/mobile/dressed_rebel_recruiter_human_female_01.py @@ -1,4 +1,10 @@ import sys +from resources.datatables import Options def setup(core, object): - return \ No newline at end of file + object.setAttachment('radial_filename', 'object/conversation'); + object.setAttachment('conversationFile','reb_recruiter') + object.setOptionsBitmask(Options.CONVERSABLE | Options.INVULNERABLE) + object.setStfFilename('mob/creature_names') + object.setStfName('rebel_recruiter') + return diff --git a/scripts/object/tangible/deed/city_deed/garden_tatooine_sml_01_deed.py b/scripts/object/tangible/deed/city_deed/garden_tatooine_sml_01_deed.py index ccad8904..07ab9319 100644 --- a/scripts/object/tangible/deed/city_deed/garden_tatooine_sml_01_deed.py +++ b/scripts/object/tangible/deed/city_deed/garden_tatooine_sml_01_deed.py @@ -1,4 +1,8 @@ import sys def setup(core, object): + object.setAttachment('radial_filename', 'deeds/structureDeed') + return + +def use(core, actor, object): return \ No newline at end of file diff --git a/scripts/object/tangible/deed/city_deed/shuttleport_tatooine_deed.py b/scripts/object/tangible/deed/city_deed/shuttleport_tatooine_deed.py index ccad8904..07ab9319 100644 --- a/scripts/object/tangible/deed/city_deed/shuttleport_tatooine_deed.py +++ b/scripts/object/tangible/deed/city_deed/shuttleport_tatooine_deed.py @@ -1,4 +1,8 @@ import sys def setup(core, object): + object.setAttachment('radial_filename', 'deeds/structureDeed') + return + +def use(core, actor, object): return \ No newline at end of file diff --git a/scripts/object/tangible/deed/vehicle_deed/landspeeder_tantive4_deed.py b/scripts/object/tangible/deed/vehicle_deed/landspeeder_tantive4_deed.py index 92a45a9d..f031d37f 100644 --- a/scripts/object/tangible/deed/vehicle_deed/landspeeder_tantive4_deed.py +++ b/scripts/object/tangible/deed/vehicle_deed/landspeeder_tantive4_deed.py @@ -1,7 +1,7 @@ import sys def setup(core, object): - object.setAttachment('radial_filename', 'vehicleDeed') + object.setAttachment('radial_filename', 'deeds/vehicleDeed') return def use(core, actor, object): @@ -21,4 +21,4 @@ def use(core, actor, object): core.simulationService.add(vehicle, vehicle.getPosition().x, vehicle.getPosition().z, True) actor.setAttachment('activeVehicleID', vehicle.getObjectID()) - return \ No newline at end of file + return diff --git a/scripts/object/tangible/terminal/terminal_bank.py b/scripts/object/tangible/terminal/terminal_bank.py index 64205c68..0a27868e 100644 --- a/scripts/object/tangible/terminal/terminal_bank.py +++ b/scripts/object/tangible/terminal/terminal_bank.py @@ -2,6 +2,6 @@ import sys def setup(core, object): object.setAttachment('radial_filename', 'terminal/bank') - core.mapService.addLocation(object.getPlanet(), 'Bank Terminal', object.getPosition().x, object.getPosition().z, 41, 42, 0) + core.mapService.addLocation(object.getPlanet(), '@map_loc_cat_n:terminal_bank', object.getPosition().x, object.getPosition().z, 2, 42, 0) return \ No newline at end of file diff --git a/scripts/object/tangible/terminal/terminal_bazaar.py b/scripts/object/tangible/terminal/terminal_bazaar.py index e94866f0..967ff912 100644 --- a/scripts/object/tangible/terminal/terminal_bazaar.py +++ b/scripts/object/tangible/terminal/terminal_bazaar.py @@ -1,7 +1,6 @@ import sys def setup(core, object): - - core.mapService.addLocation(object.getPlanet(), 'Bazaar Terminal', object.getPosition().x, object.getPosition().z, 41, 43, 0) + core.mapService.addLocation(object.getPlanet(), '@map_loc_cat_n:terminal_bazaar', object.getPosition().x, object.getPosition().z, 41, 43, 0) return \ No newline at end of file diff --git a/scripts/object/tangible/terminal/terminal_city_junk_dealer.py b/scripts/object/tangible/terminal/terminal_city_junk_dealer.py index ccad8904..f09f88cc 100644 --- a/scripts/object/tangible/terminal/terminal_city_junk_dealer.py +++ b/scripts/object/tangible/terminal/terminal_city_junk_dealer.py @@ -1,4 +1,5 @@ import sys def setup(core, object): + core.mapService.addLocation(object.getPlanet(), '@map_loc_cat_n:junk_dealer', object.getPosition().x, object.getPosition().z, 26, 81, 0) return \ No newline at end of file diff --git a/scripts/object/tangible/terminal/terminal_cloning.py b/scripts/object/tangible/terminal/terminal_cloning.py index dc256f9a..46138012 100644 --- a/scripts/object/tangible/terminal/terminal_cloning.py +++ b/scripts/object/tangible/terminal/terminal_cloning.py @@ -2,5 +2,6 @@ import sys def setup(core, object): object.setAttachment('radial_filename', 'terminal/cloning_terminal') + return \ No newline at end of file diff --git a/scripts/object/tangible/terminal/terminal_mission_artisan.py b/scripts/object/tangible/terminal/terminal_mission_artisan.py index 911010d8..6bface4e 100644 --- a/scripts/object/tangible/terminal/terminal_mission_artisan.py +++ b/scripts/object/tangible/terminal/terminal_mission_artisan.py @@ -2,6 +2,6 @@ import sys def setup(core, object): - core.mapService.addLocation(object.getPlanet(), 'Artisan Mission Terminal', object.getPosition().x, object.getPosition().z, 41, 21, 0) + core.mapService.addLocation(object.getPlanet(), '@map_loc_cat_n:terminal_mission_artisan', object.getPosition().x, object.getPosition().z, 41, 76, 0) return \ No newline at end of file diff --git a/scripts/object/tangible/terminal/terminal_mission_entertainer.py b/scripts/object/tangible/terminal/terminal_mission_entertainer.py index 433b5f91..31bc4a90 100644 --- a/scripts/object/tangible/terminal/terminal_mission_entertainer.py +++ b/scripts/object/tangible/terminal/terminal_mission_entertainer.py @@ -1,7 +1,6 @@ import sys def setup(core, object): - - core.mapService.addLocation(object.getPlanet(), 'Entertainer Mission Terminal', object.getPosition().x, object.getPosition().z, 41, 24, 0) - return - \ No newline at end of file + object.setAttachment("terminalType", 2) + core.mapService.addLocation(object.getPlanet(), '@map_loc_cat_n:terminal_mission_entertainer', object.getPosition().x, object.getPosition().z, 41, 75, 0) + return \ No newline at end of file diff --git a/scripts/object/tangible/terminal/terminal_mission_imperial.py b/scripts/object/tangible/terminal/terminal_mission_imperial.py index 8e4773b5..216f3bfc 100644 --- a/scripts/object/tangible/terminal/terminal_mission_imperial.py +++ b/scripts/object/tangible/terminal/terminal_mission_imperial.py @@ -1,7 +1,6 @@ import sys def setup(core, object): - - core.mapService.addLocation(object.getPlanet(), 'Imperial Mission Terminal', object.getPosition().x, object.getPosition().z, 41, 46, 0) + core.mapService.addLocation(object.getPlanet(), '@map_loc_cat_n:terminal_mission_imperial', object.getPosition().x, object.getPosition().z, 41, 80, 0) return \ No newline at end of file diff --git a/scripts/object/tangible/terminal/terminal_mission_rebel.py b/scripts/object/tangible/terminal/terminal_mission_rebel.py index 0bb50bbe..f435f149 100644 --- a/scripts/object/tangible/terminal/terminal_mission_rebel.py +++ b/scripts/object/tangible/terminal/terminal_mission_rebel.py @@ -1,7 +1,6 @@ import sys def setup(core, object): - - core.mapService.addLocation(object.getPlanet(), 'Rebel Mission Terminal', object.getPosition().x, object.getPosition().z, 41, 45, 0) + core.mapService.addLocation(object.getPlanet(), '@map_loc_cat_n:terminal_mission_rebel', object.getPosition().x, object.getPosition().z, 41, 79, 0) return \ No newline at end of file diff --git a/scripts/object/tangible/terminal/terminal_mission_scout.py b/scripts/object/tangible/terminal/terminal_mission_scout.py index ccad8904..eb7c1e2a 100644 --- a/scripts/object/tangible/terminal/terminal_mission_scout.py +++ b/scripts/object/tangible/terminal/terminal_mission_scout.py @@ -1,4 +1,5 @@ import sys def setup(core, object): + core.mapService.addLocation(object.getPlanet(), '@map_loc_cat_n:terminal_mission_scout', object.getPosition().x, object.getPosition().z, 41, 77, 0) return \ No newline at end of file diff --git a/scripts/radial/terminal/city_maintenance_terminal.py b/scripts/radial/terminal/city_maintenance_terminal.py index ef951426..e5bab716 100644 --- a/scripts/radial/terminal/city_maintenance_terminal.py +++ b/scripts/radial/terminal/city_maintenance_terminal.py @@ -24,6 +24,10 @@ def createRadial(core, owner, target, radials): 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(3, 231, 0, 'Add 10 citizens')) + radials.add(RadialOptions(3, 232, 0, 'Deduct 10 citizens')) return @@ -80,14 +84,26 @@ def handleSelection(core, owner, target, option): if owner is not None: handleCitizenList(core, owner, target, option) return - -def handleSetCityName(core, owner, target, option): - window = core.suiService.createInputBox(2,'@city/city:city_name_new_t','@city/city:city_name_new_d', owner, target, 0) - returnList = Vector() - returnList.add('txtInput:LocalText') - window.addHandler(0, '', Trigger.TRIGGER_OK, returnList, setnameCallBack) - window.addHandler(1, '', Trigger.TRIGGER_CANCEL, returnList, setnameCallBack) - core.suiService.openSUIWindow(window); + + 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 + +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): diff --git a/scripts/static_spawns/corellia/placeholder.txt b/scripts/static_spawns/corellia/placeholder.txt new file mode 100644 index 00000000..e69de29b diff --git a/scripts/static_spawns/dantooine/placeholder.txt b/scripts/static_spawns/dantooine/placeholder.txt new file mode 100644 index 00000000..e69de29b diff --git a/scripts/static_spawns/dathomir/placeholder.txt b/scripts/static_spawns/dathomir/placeholder.txt new file mode 100644 index 00000000..e69de29b diff --git a/scripts/static_spawns/endor/placeholder.txt b/scripts/static_spawns/endor/placeholder.txt new file mode 100644 index 00000000..e69de29b diff --git a/scripts/static_spawns/kaas.py b/scripts/static_spawns/kaas.py index b576e2da..f21c8441 100644 --- a/scripts/static_spawns/kaas.py +++ b/scripts/static_spawns/kaas.py @@ -14,14 +14,14 @@ def addPlanetSpawns(core, planet): objSvc = core.objectService #Dark Temple Area #Structures - stcSvc.spawnObject('object/building/military/shared_military_base_police_station_imperial_lok_otto.iff', 'kaas', long(0), float(-5117.8), float(80.0), float(-2314.1), float(0), float(0)) - stcSvc.spawnObject('object/building/player/shared_player_house_corellia_medium_style_01.iff', 'kaas', long(0), float(-5078.6), float(80.0), float(-2302.5), float(0), float(0)) - stcSvc.spawnObject('object/building/general/shared_bunker_imperial_weapons_research_facility_01.iff', 'kaas', long(0), float(-5159.5), float(80.0), float(-2298.7), float(0), float(0)) - stcSvc.spawnObject('object/building/content/aurilia/shared_aurilia_pyramid_hut.iff', 'kaas', long(0), float(-5163.9), float(79.0), float(-2369.6), float(0.71), float(0.71)) - stcSvc.spawnObject('object/building/content/aurilia/shared_aurilia_pyramid_hut.iff', 'kaas', long(0), float(-5163.9), float(79.0), float(-2351.6), float(0.71), float(0.71)) - stcSvc.spawnObject('object/building/content/aurilia/shared_aurilia_pyramid_hut.iff', 'kaas', long(0), float(-5072.1), float(79.0), float(-2369.6), float(-0.71), float(0.71)) - stcSvc.spawnObject('object/building/content/aurilia/shared_aurilia_pyramid_hut.iff', 'kaas', long(0), float(-5072.1), float(79.0), float(-2351.6), float(-0.71), float(0.71)) - stcSvc.spawnObject('object/building/military/shared_outpost_cloning_facility_s02.iff', long(0), 'kaas', long(0), float(-5072.1), float(80.0), float(-2279.5), float(0.71), float(0), float(-0.71), float(0)) + #stcSvc.spawnObject('object/building/military/shared_military_base_police_station_imperial_lok_otto.iff', 'kaas', long(0), float(-5117.8), float(80.0), float(-2314.1), float(0), float(0)) + #stcSvc.spawnObject('object/building/player/shared_player_house_corellia_medium_style_01.iff', 'kaas', long(0), float(-5078.6), float(80.0), float(-2302.5), float(0), float(0)) + #stcSvc.spawnObject('object/building/general/shared_bunker_imperial_weapons_research_facility_01.iff', 'kaas', long(0), float(-5159.5), float(80.0), float(-2298.7), float(0), float(0)) + #stcSvc.spawnObject('object/building/content/aurilia/shared_aurilia_pyramid_hut.iff', 'kaas', long(0), float(-5163.9), float(79.0), float(-2369.6), float(0.71), float(0.71)) + #stcSvc.spawnObject('object/building/content/aurilia/shared_aurilia_pyramid_hut.iff', 'kaas', long(0), float(-5163.9), float(79.0), float(-2351.6), float(0.71), float(0.71)) + #stcSvc.spawnObject('object/building/content/aurilia/shared_aurilia_pyramid_hut.iff', 'kaas', long(0), float(-5072.1), float(79.0), float(-2369.6), float(-0.71), float(0.71)) + #stcSvc.spawnObject('object/building/content/aurilia/shared_aurilia_pyramid_hut.iff', 'kaas', long(0), float(-5072.1), float(79.0), float(-2351.6), float(-0.71), float(0.71)) + #stcSvc.spawnObject('object/building/military/shared_outpost_cloning_facility_s02.iff', 'kaas', long(0), float(-5072.1), float(80.0), float(-2279.5), float(0.71), float(0), float(-0.71), float(0)) #Terminals stcSvc.spawnObject('object/tangible/terminal/shared_terminal_bank.iff', 'kaas', long(0), float(-5080.8), float(80.0), float(-2275.7), float(-0.71), float(0.71)) @@ -58,20 +58,20 @@ def addPlanetSpawns(core, planet): #Village of the Descendants Area - stcSvc.spawnObject('object/building/general/shared_cave_01.iff', 'kaas', long(0), float(3348.1), float(110), float(2562.1), float(0), float(0)) + #stcSvc.spawnObject('object/building/general/shared_cave_01.iff', 'kaas', long(0), float(3348.1), float(110), float(2562.1), float(0), float(0)) #Kaas City Ruins #Tomb of Vitiate #Northwest Cave - stcSvc.spawnObject('object/building/general/shared_cave_01.iff', 'kaas', long(0), float(-6135.3), float(185), float(6575.0), float(0), float(0)) + #stcSvc.spawnObject('object/building/general/shared_cave_01.iff', 'kaas', long(0), float(-6135.3), float(185), float(6575.0), float(0), float(0)) #Abandoned Separatist Base - stcSvc.spawnObject('object/building/military/shared_military_base_police_station_rebel_style_01.iff', 'kaas', long(0), float(-3538), float(80), float(6758), float(0), float(0)) + #stcSvc.spawnObject('object/building/military/shared_military_base_police_station_rebel_style_01.iff', 'kaas', long(0), float(-3538), float(80), float(6758), float(0), float(0)) #Sith Meditation Chamber - stcSvc.spawnObject('object/building/player/shared_player_house_sith_meditation_room.iff', 'kaas', long(0), float(4766), float(126), float(-7307), float(0), float(0)) + #stcSvc.spawnObject('object/building/player/shared_player_house_sith_meditation_room.iff', 'kaas', long(0), float(4766), float(126), float(-7307), float(0), float(0)) #Large Ruin stcSvc.spawnObject('object/static/structure/dantooine/shared_dant_jedi_main_structure.iff', 'kaas', long(0), float(-434), float(77), float(-2252), float(0), float(0)) diff --git a/scripts/static_spawns/kaas/placeholder.txt b/scripts/static_spawns/kaas/placeholder.txt new file mode 100644 index 00000000..e69de29b diff --git a/scripts/static_spawns/kashyyyk_main/placeholder.txt b/scripts/static_spawns/kashyyyk_main/placeholder.txt new file mode 100644 index 00000000..e69de29b diff --git a/scripts/static_spawns/lok/placeholder.txt b/scripts/static_spawns/lok/placeholder.txt new file mode 100644 index 00000000..e69de29b diff --git a/scripts/static_spawns/mustafar/placeholder.txt b/scripts/static_spawns/mustafar/placeholder.txt new file mode 100644 index 00000000..e69de29b diff --git a/scripts/static_spawns/naboo/placeholder.txt b/scripts/static_spawns/naboo/placeholder.txt new file mode 100644 index 00000000..e69de29b diff --git a/scripts/static_spawns/rori/placeholder.txt b/scripts/static_spawns/rori/placeholder.txt new file mode 100644 index 00000000..e69de29b diff --git a/scripts/static_spawns/talus/placeholder.txt b/scripts/static_spawns/talus/placeholder.txt new file mode 100644 index 00000000..e69de29b diff --git a/scripts/static_spawns/tatooine.py b/scripts/static_spawns/tatooine.py index 1d7b383b..1ce34894 100644 --- a/scripts/static_spawns/tatooine.py +++ b/scripts/static_spawns/tatooine.py @@ -23,6 +23,13 @@ def addPlanetSpawns(core, planet): stcSvc.spawnObject('object/mobile/shared_junk_dealer_m_01.iff', 'tatooine', long(0), float(3525), float(4), float(-4804), float(0.70), float(0.71)) #stcSvc.spawnObject('object/mobile/shared_3po_protocol_droid_red.iff', 'tatooine', long(26582), float(-14.3), float(2.0), float(47.4), float(0.70), float(0.71)) + + impRecruiter = stcSvc.spawnObject('object/mobile/shared_dressed_imperial_officer_f.iff', 'tatooine', long(1280132), float(-6), float(1), float(9.2), float(0.70), float(0.71)) + impRecruiter.setOptionsBitmask(264) + + rebRecruiter = stcSvc.spawnObject('object/mobile/shared_dressed_rebel_recruiter_human_female_01.iff', 'tatooine', long(1082887), float(-30.5), float(-0.5), float(6.2), float(0.70), float(0.71)) + rebRecruiter.setOptionsBitmask(264) + return diff --git a/scripts/static_spawns/tatooine/placeholder.txt b/scripts/static_spawns/tatooine/placeholder.txt new file mode 100644 index 00000000..e69de29b diff --git a/scripts/static_spawns/yavin4/placeholder.txt b/scripts/static_spawns/yavin4/placeholder.txt new file mode 100644 index 00000000..e69de29b diff --git a/src/main/NGECore.java b/src/main/NGECore.java index 18f15e3d..1fb03377 100644 --- a/src/main/NGECore.java +++ b/src/main/NGECore.java @@ -45,9 +45,13 @@ import com.sleepycat.persist.EntityCursor; import protocol.swg.chat.ChatSystemMessage; import net.engio.mbassy.bus.config.BusConfiguration; +import resources.common.BountyListItem; import resources.common.RadialOptions; import resources.common.ThreadMonitor; import resources.objects.creature.CreatureObject; +import resources.objects.guild.GuildObject; +import resources.objects.resource.GalacticResource; +import resources.objects.resource.ResourceRoot; import services.AttributeService; import services.BuffService; import services.CharacterService; @@ -71,8 +75,11 @@ import services.SurveyService; import services.TerrainService; import services.WeatherService; import services.ai.AIService; +import services.bazaar.AuctionItem; import services.bazaar.BazaarService; +import services.chat.ChatRoom; import services.chat.ChatService; +import services.chat.Mail; import services.collections.CollectionService; import services.combat.CombatService; import services.command.CombatCommand; @@ -83,6 +90,8 @@ import services.guild.GuildService; import services.LoginService; import services.map.MapService; import services.mission.MissionService; +import services.object.DuplicateId; +import services.object.ObjectId; import services.object.ObjectService; import services.object.UpdateService; import services.pet.MountService; @@ -110,6 +119,7 @@ import engine.resources.config.Config; import engine.resources.config.DefaultConfig; import engine.resources.container.Traverser; import engine.resources.database.DatabaseConnection; +import engine.resources.database.ODBCursor; import engine.resources.database.ObjectDatabase; import engine.resources.objects.SWGObject; import engine.resources.scene.Point3D; @@ -199,7 +209,6 @@ public class NGECore { public InteractiveJythonAcceptor jythonAcceptor; private InteractiveJythonServer jythonServer; - private ObjectDatabase creatureODB; private ObjectDatabase mailODB; private ObjectDatabase guildODB; private ObjectDatabase objectIdODB; @@ -208,11 +217,11 @@ public class NGECore { private BusConfiguration eventBusConfig = BusConfiguration.Default(1, new ThreadPoolExecutor(1, 4, 1, TimeUnit.MINUTES, new LinkedBlockingQueue())); - private ObjectDatabase buildingODB; private ObjectDatabase auctionODB; private ObjectDatabase resourcesODB; private ObjectDatabase resourceRootsODB; private ObjectDatabase resourceHistoryODB; + private ObjectDatabase swgObjectODB; private ObjectDatabase bountiesODB; public static boolean PACKET_DEBUG = false; @@ -264,18 +273,17 @@ public class NGECore { } setGalaxyStatus(1); - creatureODB = new ObjectDatabase("creature", true, false, true); - buildingODB = new ObjectDatabase("building", true, false, true); - mailODB = new ObjectDatabase("mails", true, false, true); - guildODB = new ObjectDatabase("guild", true, false, true); - objectIdODB = new ObjectDatabase("oids", true, false, false); - duplicateIdODB = new ObjectDatabase("doids", true, false, true); - chatRoomODB = new ObjectDatabase("chatRooms", true, false, true); - resourcesODB = new ObjectDatabase("resources", true, false, true); - resourceRootsODB = new ObjectDatabase("resourceroots", true, false, true); - resourceHistoryODB = new ObjectDatabase("resourcehistory", true, false, true); - auctionODB = new ObjectDatabase("auction", true, false, true); - bountiesODB = new ObjectDatabase("bounties", true, false, true); + swgObjectODB = new ObjectDatabase("swgobjects", true, true, true, SWGObject.class); + mailODB = new ObjectDatabase("mails", true, true, true, Mail.class); + guildODB = new ObjectDatabase("guild", true, true, true, GuildObject.class); + objectIdODB = new ObjectDatabase("oids", true, true, true, ObjectId.class); + duplicateIdODB = new ObjectDatabase("doids", true, true, true, DuplicateId.class); + chatRoomODB = new ObjectDatabase("chatRooms", true, true, true, ChatRoom.class); + resourcesODB = new ObjectDatabase("resources", true, true, true, GalacticResource.class); + resourceRootsODB = new ObjectDatabase("resourceroots", true, true, true, ResourceRoot.class); + resourceHistoryODB = new ObjectDatabase("resourcehistory", true, true, true, GalacticResource.class); + auctionODB = new ObjectDatabase("auction", true, true, true, AuctionItem.class); + bountiesODB = new ObjectDatabase("bounties", true, true, true, BountyListItem.class); // Services loginService = new LoginService(this); @@ -483,6 +491,7 @@ public class NGECore { spawnService.loadMobileTemplates(); spawnService.loadLairTemplates(); spawnService.loadLairGroups(); + spawnService.loadDynamicGroups();; spawnService.loadSpawnAreas(); equipmentService.loadBonusSets(); @@ -497,24 +506,21 @@ public class NGECore { } private void cleanupCreatureODB() { - EntityCursor cursor = creatureODB.getCursor(Long.class, CreatureObject.class); + ODBCursor cursor = swgObjectODB.getCursor(); - Iterator it = cursor.iterator(); List deletedObjects = new ArrayList(); - while(it.hasNext()) { - CreatureObject creature = it.next(); - if(!characterService.playerExists(creature.getObjectID())) - deletedObjects.add(creature); + while(cursor.hasNext()) { + SWGObject creature = (SWGObject) cursor.next(); + if(!characterService.playerExists(creature.getObjectID()) && creature instanceof CreatureObject) + deletedObjects.add((CreatureObject) creature); } - cursor.close(); - Transaction txn = creatureODB.getEnvironment().beginTransaction(null, null); for(CreatureObject creature : deletedObjects) { - creatureODB.delete(creature.getObjectID(), Long.class, CreatureObject.class, txn); + swgObjectODB.remove(creature.getObjectID()); } - txn.commitSync(); + System.out.println("Deleted " + deletedObjects.size() + " creatures."); } @@ -600,8 +606,8 @@ public class NGECore { return databaseConnection2; } - public ObjectDatabase getCreatureODB() { - return creatureODB; + public ObjectDatabase getSWGObjectODB() { + return swgObjectODB; } public ObjectDatabase getMailODB() { @@ -611,11 +617,7 @@ public class NGECore { public ObjectDatabase getGuildODB() { return guildODB; } - - public ObjectDatabase getBuildingODB() { - return buildingODB; - } - + public ObjectDatabase getObjectIdODB() { return objectIdODB; } @@ -744,6 +746,19 @@ public class NGECore { return System.currentTimeMillis() - galacticTime; } + public void closeODBs() { + swgObjectODB.close(); + mailODB.close(); + guildODB.close(); + chatRoomODB.close(); + resourcesODB.close(); + resourceRootsODB.close(); + resourceHistoryODB.close(); + objectIdODB.close(); + duplicateIdODB.close(); + auctionODB.close(); + } + } diff --git a/src/protocol/swg/CommPlayerMessage.java b/src/protocol/swg/CommPlayerMessage.java index 5d1274c8..9acde60c 100644 --- a/src/protocol/swg/CommPlayerMessage.java +++ b/src/protocol/swg/CommPlayerMessage.java @@ -25,15 +25,16 @@ import java.nio.ByteOrder; import org.apache.mina.core.buffer.IoBuffer; -import resources.common.Console; +import engine.resources.common.CRC; import resources.common.OutOfBand; -import resources.common.StringUtilities; public class CommPlayerMessage extends SWGMessage { private long objectId; + private String model; private OutOfBand outOfBand; - + private int time; + public CommPlayerMessage(long objectId, OutOfBand outOfBand) { this.objectId = objectId; this.outOfBand = outOfBand; @@ -46,28 +47,35 @@ public class CommPlayerMessage extends SWGMessage { @Override public IoBuffer serialize() { - IoBuffer buffer = IoBuffer.allocate(200).order(ByteOrder.LITTLE_ENDIAN); + IoBuffer buffer = IoBuffer.allocate(50).order(ByteOrder.LITTLE_ENDIAN); + buffer.setAutoExpand(true); + buffer.putShort((short) 2); buffer.putInt(0x594AD258); buffer.put((byte) 0); // aurebesh borders on comm, space version? Can cause crashes buffer.putLong(objectId); - /* Seen numbers: - * 52 (Starting Station Comms) - * 54 (Tansarii Comms) - * 57 (Supply Drops) - * 58 (Faction Covert->Overt) - * 68 (Imperial stop) - */ buffer.put(outOfBand.serialize().array()); // Officer Supply Drop: 0x3E894347 // Rebel Faction Dude: 0x528CB3D7 - buffer.putInt(0x528CB3D7); // model crc, can be anything w/o crashing + if (model == null) + buffer.putInt(0x3E894347); + else + buffer.putInt(CRC.StringtoCRC(model)); buffer.putInt(0); // sound buffer.putShort((short) 0); // unk - buffer.putShort((short) 16576); // comm display time, unsure on how it's calculated (probably milliseconds) + if (time == 0) + buffer.putShort((short) 16576); + else + buffer.putShort((short) time); buffer.flip(); - Console.println("CPM: " + StringUtilities.bytesToHex(buffer.array())); return buffer; } + + public void setModel(String model) { + this.model = model; + } + public void setTime(int time) { + this.time = time; + } } diff --git a/src/resources/buffs/Buff.java b/src/resources/buffs/Buff.java index 52b9613e..24d4937f 100644 --- a/src/resources/buffs/Buff.java +++ b/src/resources/buffs/Buff.java @@ -21,6 +21,7 @@ ******************************************************************************/ package resources.buffs; +import java.io.Serializable; import java.nio.ByteOrder; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledFuture; @@ -40,10 +41,11 @@ import com.sleepycat.persist.model.Persistent; import engine.resources.common.CRC; @Persistent(version=10) -public class Buff implements IDelta { +public class Buff implements IDelta, Serializable { + private static final long serialVersionUID = 1L; @NotPersistent - private SimpleBufferAllocator bufferPool = new SimpleBufferAllocator(); + private transient SimpleBufferAllocator bufferPool = new SimpleBufferAllocator(); private String group1, group2; private int priority; private float duration; @@ -65,7 +67,7 @@ public class Buff implements IDelta { private int totalPlayTime; private byte decayCounter = 0; @NotPersistent - private ScheduledFuture removalTask; + private transient ScheduledFuture removalTask; private int stacks = 1; private long groupBufferId; private int buffCRC; diff --git a/src/resources/buffs/BuffItem.java b/src/resources/buffs/BuffItem.java index ae302027..208df3f6 100644 --- a/src/resources/buffs/BuffItem.java +++ b/src/resources/buffs/BuffItem.java @@ -21,10 +21,14 @@ ******************************************************************************/ package resources.buffs; +import java.io.Serializable; + import com.sleepycat.persist.model.Persistent; @Persistent -public class BuffItem { +public class BuffItem implements Serializable { + + private static final long serialVersionUID = 1L; private int affectAmount; private int entertainerBonus; private int invested; diff --git a/src/resources/buffs/DamageOverTime.java b/src/resources/buffs/DamageOverTime.java index 8a21306a..d1aa8bc9 100644 --- a/src/resources/buffs/DamageOverTime.java +++ b/src/resources/buffs/DamageOverTime.java @@ -21,20 +21,22 @@ ******************************************************************************/ package resources.buffs; +import java.io.Serializable; import java.util.concurrent.ScheduledFuture; import com.sleepycat.persist.model.NotPersistent; import com.sleepycat.persist.model.Persistent; @Persistent(version=1) -public class DamageOverTime { +public class DamageOverTime implements Serializable { + private static final long serialVersionUID = 1L; private Buff buff; private String type; private int duration; private int intensity; @NotPersistent - private ScheduledFuture task; + private transient ScheduledFuture task; private long startTime; private String commandName; diff --git a/src/resources/common/AString.java b/src/resources/common/AString.java index 1a9f73f2..14677cb6 100644 --- a/src/resources/common/AString.java +++ b/src/resources/common/AString.java @@ -21,6 +21,7 @@ ******************************************************************************/ package resources.common; +import java.io.Serializable; import java.nio.ByteOrder; import org.apache.mina.core.buffer.IoBuffer; @@ -30,8 +31,9 @@ import com.sleepycat.persist.model.Persistent; import resources.objects.Delta; @Persistent -public final class AString extends Delta { +public final class AString extends Delta implements Serializable { + private static final long serialVersionUID = 1L; private String string; public AString() { diff --git a/src/resources/common/BountyListItem.java b/src/resources/common/BountyListItem.java index 696d24df..10033656 100644 --- a/src/resources/common/BountyListItem.java +++ b/src/resources/common/BountyListItem.java @@ -21,15 +21,17 @@ ******************************************************************************/ package resources.common; +import java.io.Serializable; import java.util.ArrayList; import java.util.List; import com.sleepycat.persist.model.Entity; import com.sleepycat.persist.model.PrimaryKey; + +@Entity(version=1) +public class BountyListItem implements Serializable { -@Entity -public class BountyListItem { - + private static final long serialVersionUID = 1L; @PrimaryKey private long objectId; private int creditReward; @@ -37,7 +39,9 @@ public class BountyListItem { private String faction; private String name; private List assignedHunters; - + private List bountyPlacers; + private int failedAttempts; + public BountyListItem() { } public BountyListItem(long objectId, int creditReward, String profession, String faction, String name) { @@ -47,6 +51,7 @@ public class BountyListItem { this.faction = faction; this.setName(name); this.setAssignedHunters(new ArrayList(3)); + this.setBountyPlacers(new ArrayList()); } public long getObjectId() { @@ -87,6 +92,10 @@ public class BountyListItem { public void addBounty(int amountToAdd) { this.creditReward += amountToAdd; } + + public void deductBounty(int amountToDeduct) { + this.creditReward = this.creditReward - amountToDeduct; + } public List getAssignedHunters() { return assignedHunters; @@ -103,4 +112,24 @@ public class BountyListItem { public void removeBountyHunter(long objectId) { assignedHunters.remove(objectId); } -} + + public List getBountyPlacers() { + return bountyPlacers; + } + + public void setBountyPlacers(List bountyPlacers) { + this.bountyPlacers = bountyPlacers; + } + + public int getFailedAttempts() { + return failedAttempts; + } + + public void setFailedAttempts(int failedAttempts) { + this.failedAttempts = failedAttempts; + } + + public void incrementFailedAttempts() { + this.failedAttempts += 1; + } +} \ No newline at end of file diff --git a/src/resources/common/UString.java b/src/resources/common/UString.java index dec215af..37564bd1 100644 --- a/src/resources/common/UString.java +++ b/src/resources/common/UString.java @@ -21,6 +21,7 @@ ******************************************************************************/ package resources.common; +import java.io.Serializable; import java.io.UnsupportedEncodingException; import com.sleepycat.persist.model.Persistent; @@ -28,8 +29,9 @@ import com.sleepycat.persist.model.Persistent; import resources.objects.Delta; @Persistent -public final class UString extends Delta { +public final class UString extends Delta implements Serializable { + private static final long serialVersionUID = 1L; private String string; public UString() { diff --git a/src/resources/gcw/CurrentServerGCWZoneHistory.java b/src/resources/gcw/CurrentServerGCWZoneHistory.java index 66874d64..c8f81fda 100644 --- a/src/resources/gcw/CurrentServerGCWZoneHistory.java +++ b/src/resources/gcw/CurrentServerGCWZoneHistory.java @@ -21,6 +21,8 @@ ******************************************************************************/ package resources.gcw; +import java.io.Serializable; + import org.apache.mina.core.buffer.IoBuffer; import com.sleepycat.persist.model.Persistent; @@ -28,8 +30,9 @@ import com.sleepycat.persist.model.Persistent; import resources.objects.Delta; @Persistent(version=0) -public class CurrentServerGCWZoneHistory extends Delta implements Cloneable { +public class CurrentServerGCWZoneHistory extends Delta implements Cloneable, Serializable { + private static final long serialVersionUID = 1L; private int lastUpdateTime; private int percent; diff --git a/src/resources/gcw/CurrentServerGCWZonePercent.java b/src/resources/gcw/CurrentServerGCWZonePercent.java index ea825d7a..6e5bf56a 100644 --- a/src/resources/gcw/CurrentServerGCWZonePercent.java +++ b/src/resources/gcw/CurrentServerGCWZonePercent.java @@ -21,6 +21,7 @@ ******************************************************************************/ package resources.gcw; +import java.io.Serializable; import java.math.BigDecimal; import java.math.MathContext; @@ -29,12 +30,12 @@ import org.apache.mina.core.buffer.IoBuffer; import com.sleepycat.persist.model.Persistent; import engine.resources.scene.Point2D; - import resources.objects.Delta; @Persistent(version=0) -public class CurrentServerGCWZonePercent extends Delta implements Cloneable { +public class CurrentServerGCWZonePercent extends Delta implements Cloneable, Serializable { + private static final long serialVersionUID = 1L; private Point2D position; private float radius = 0; private BigDecimal weight; diff --git a/src/resources/gcw/OtherServerGCWZonePercent.java b/src/resources/gcw/OtherServerGCWZonePercent.java index ab8048eb..15d9da9d 100644 --- a/src/resources/gcw/OtherServerGCWZonePercent.java +++ b/src/resources/gcw/OtherServerGCWZonePercent.java @@ -21,6 +21,8 @@ ******************************************************************************/ package resources.gcw; +import java.io.Serializable; + import org.apache.mina.core.buffer.IoBuffer; import com.sleepycat.persist.model.Persistent; @@ -28,8 +30,9 @@ import com.sleepycat.persist.model.Persistent; import resources.objects.Delta; @Persistent(version=0) -public class OtherServerGCWZonePercent extends Delta implements Cloneable { +public class OtherServerGCWZonePercent extends Delta implements Cloneable, Serializable { + private static final long serialVersionUID = 1L; private String zone = ""; private int percent = 50; diff --git a/src/resources/guild/Guild.java b/src/resources/guild/Guild.java index 5651c2d0..7ecdd2bb 100644 --- a/src/resources/guild/Guild.java +++ b/src/resources/guild/Guild.java @@ -21,6 +21,7 @@ ******************************************************************************/ package resources.guild; +import java.io.Serializable; import java.util.List; import org.apache.mina.core.buffer.IoBuffer; @@ -28,12 +29,12 @@ import org.apache.mina.core.buffer.IoBuffer; import com.sleepycat.persist.model.Persistent; import resources.objects.Delta; - import engine.resources.objects.SWGObject; @Persistent(version=0) -public class Guild extends Delta { +public class Guild extends Delta implements Serializable { + private static final long serialVersionUID = 1L; private int id; private String abbreviation; private String name; diff --git a/src/resources/loot/LootGroup.java b/src/resources/loot/LootGroup.java index 8666014d..a43e435d 100644 --- a/src/resources/loot/LootGroup.java +++ b/src/resources/loot/LootGroup.java @@ -21,6 +21,8 @@ ******************************************************************************/ package resources.loot; +import java.io.Serializable; + import com.sleepycat.persist.model.Persistent; /** @@ -28,8 +30,10 @@ import com.sleepycat.persist.model.Persistent; */ @Persistent(version=0) -public class LootGroup { +public class LootGroup implements Serializable { + private static final long serialVersionUID = 1L; + private String[] lootPoolNames; private double[] lootPoolChances; private double lootGroupChance; diff --git a/src/resources/objectives/BountyMissionObjective.java b/src/resources/objectives/BountyMissionObjective.java index 96b90c88..caa8edbf 100644 --- a/src/resources/objectives/BountyMissionObjective.java +++ b/src/resources/objectives/BountyMissionObjective.java @@ -1,80 +1,263 @@ -/******************************************************************************* - * Copyright (c) 2013 - * - * This File is part of NGECore2. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Using NGEngine to work with NGECore2 is making a combined work based on NGEngine. - * Therefore all terms and conditions of the GNU Lesser General Public License cover the combination. - ******************************************************************************/ -package resources.objectives; - -import java.util.Random; - -import engine.resources.scene.Point3D; -import main.NGECore; -import resources.common.BountyListItem; -import resources.objects.creature.CreatureObject; -import resources.objects.mission.MissionObject; -import services.mission.MissionObjective; - -public class BountyMissionObjective extends MissionObjective { - - private Point3D lastKnownLocation; - private long markObjId; - - public BountyMissionObjective(MissionObject parent) { - super(parent); - } - - @Override - public void activate(NGECore core, CreatureObject player) { - if (isActivated()) - return; - - BountyListItem bountyTarget = core.missionService.getBountyListItem(getMissionObject().getBountyObjId()); - - setMarkObjId(bountyTarget.getObjectId()); - - // TODO: Change this to a comm message. - player.sendSystemMessage("@mission/mission_bounty_informant:target_hard_" + Integer.toString(new Random().nextInt(5)), (byte) 0); - - - } - - @Override - public void complete(NGECore core, CreatureObject player) { - - } - - @Override - public void abort(NGECore core, CreatureObject player) { - - } - - @Override - public void update(NGECore core, CreatureObject player) { - - } - - public Point3D getLastKnownLocation() { return lastKnownLocation; } - - public void setLastKnownLocation(Point3D lastKnownLocation) { this.lastKnownLocation = lastKnownLocation; } - - public long getMarkObjId() { return markObjId; } - - public void setMarkObjId(long markObjId) { this.markObjId = markObjId; } - -} +/******************************************************************************* + * Copyright (c) 2013 + * + * This File is part of NGECore2. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + * + * Using NGEngine to work with NGECore2 is making a combined work based on NGEngine. + * Therefore all terms and conditions of the GNU Lesser General Public License cover the combination. + ******************************************************************************/ +package resources.objectives; + +import java.util.Random; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.TimeUnit; + +import protocol.swg.CommPlayerMessage; +import engine.resources.container.Traverser; +import engine.resources.objects.SWGObject; +import engine.resources.scene.Point3D; +import main.NGECore; +import resources.common.BountyListItem; +import resources.common.OutOfBand; +import resources.common.ProsePackage; +import resources.datatables.DisplayType; +import resources.objects.creature.CreatureObject; +import resources.objects.mission.MissionObject; +import resources.objects.waypoint.WaypointObject; +import services.chat.Mail; +import services.mission.MissionObjective; + +public class BountyMissionObjective extends MissionObjective { + + private Point3D lastKnownLocation; + private String lastKnownPlanet; + private ScheduledFuture locationUpdater; + private long markObjId; + + private boolean seekerActive = false; + private String seekerPlanet = ""; + private boolean arakydActive = false; + + public BountyMissionObjective(MissionObject parent) { + super(parent); + } + + @Override + public void activate(NGECore core, CreatureObject player) { + if (isActivated()) + return; + + BountyListItem bountyTarget = core.missionService.getBountyListItem(getMissionObject().getBountyObjId()); + + if (bountyTarget == null) { + core.missionService.handleMissionAbort(player, getMissionObject()); + player.sendSystemMessage("@bountyhunter:null_mission", DisplayType.Broadcast); + return; + } + + bountyTarget.addBountyHunter(player.getObjectId()); + + setMarkObjId(bountyTarget.getObjectId()); + + String message = "@mission/mission_bounty_informant:target_hard_" + Integer.toString(new Random().nextInt(4) + 1); + + CommPlayerMessage comm = new CommPlayerMessage(player.getObjectId(), new OutOfBand(new ProsePackage(message))); + comm.setTime(5000); + switch (bountyTarget.getFaction()) { + case "neutral": + comm.setModel("object/mobile/shared_dressed_assassin_mission_giver_0" + Integer.toString(new Random().nextInt(2) + 1) + ".iff"); + break; + case "rebel": + comm.setModel("object/mobile/shared_dressed_assassin_mission_giver_imp_hum_m_0" + Integer.toString(new Random().nextInt(2) + 1) + ".iff"); + break; + case "imperial": + comm.setModel("object/mobile/shared_dressed_assassin_mission_giver_reb_0" + Integer.toString(new Random().nextInt(2) + 1) + ".iff"); + break; + } //Could also be: object/mobile/shared_bounty_guild_bounty_check.iff || object/mobile/shared_bounty_check_fugitive_x.iff + + player.getClient().getSession().write(comm.serialize()); + } + + @Override + public void complete(NGECore core, CreatureObject player) { + BountyListItem bounty = core.missionService.getBountyListItem(markObjId); + + if (bounty == null) + return; + + int reward = getMissionObject().getCreditReward(); + + if (bounty.getCreditReward() - reward == 0) + player.addBankCredits(reward); + else + player.addBankCredits(bounty.getCreditReward()); + + notifyBountyPlacers(core, player, bounty); + + clearActiveMissions(core, bounty); + + core.missionService.removeBounty(markObjId); + } + + @Override + public void abort(NGECore core, CreatureObject player) { + BountyListItem bounty = core.missionService.getBountyListItem(markObjId); + + if (bounty == null) + return; + + bounty.removeBountyHunter(player.getObjectId()); + } + + @Override + public void update(NGECore core, CreatureObject player) { + + } + + public void notifyBountyPlacers(NGECore core, CreatureObject player, BountyListItem bounty) { + + String message = "Dear Sir or Madam,\nThe Galactic Bounty Network wishes to inform you that the bounty that you placed on the head of "+ bounty.getName() + + " has been claimed by the bounty hunter, " + player.getCustomName() + ".\nThank you for your patronage, and have a nice day."; + + bounty.getBountyPlacers().forEach(id -> { + Mail bountyMail = new Mail(); + bountyMail.setMailId(core.chatService.generateMailId()); + bountyMail.setTimeStamp((int) (new java.util.Date().getTime() / 1000)); + bountyMail.setRecieverId(id); + bountyMail.setSubject("Bounty Claim Notification"); + bountyMail.setSenderName("Galactic Bounty Network"); + bountyMail.setMessage(message); + bountyMail.setStatus(Mail.NEW); + + core.chatService.storePersistentMessage(bountyMail); + + SWGObject obj = core.objectService.getObject(id); + if (obj != null) + core.chatService.sendPersistentMessageHeader(obj.getClient(), bountyMail); + }); + } + + public void clearActiveMissions(NGECore core, BountyListItem bounty) { + bounty.getAssignedHunters().forEach(id -> { + CreatureObject hunter = (CreatureObject) core.objectService.getObject(id); + + if (hunter != null) { + hunter.sendSystemMessage(new OutOfBand(new ProsePackage("@bounty_hunter:bounty_failed_hunter", "TT", getMissionObject().getGrandparent().getObjectId())), DisplayType.Broadcast); + hunter.getSlottedObject("datapad").viewChildren(hunter, true, false, new Traverser() { + @Override + public void process(SWGObject item) { + if (item instanceof MissionObject) { + MissionObject mission = (MissionObject) item; + if (mission.getMissionType().equals("bounty")) { + core.missionService.handleMissionAbort(hunter, mission); + } + } + } + }); + } + }); + } + + public void checkBountyActiveStatus(NGECore core) { + BountyListItem bountyTarget = core.missionService.getBountyListItem(getMissionObject().getBountyObjId()); + CreatureObject player = (CreatureObject) getMissionObject().getGrandparent(); + + if (bountyTarget == null || !bountyTarget.getAssignedHunters().contains(player.getObjectId())) { + player.sendSystemMessage("@bounty_hunter:bounty_incomplete", DisplayType.Broadcast); + core.missionService.handleMissionAbort(player, getMissionObject(), true); + } + } + + public void beginSeekerUpdates(NGECore core) { + + if (!seekerActive) { + setSeekerActive(true); + setSeekerPlanet(getMissionObject().getGrandparent().getPlanet().getName()); + + ScheduledFuture updates = Executors.newScheduledThreadPool(1).scheduleAtFixedRate(new Runnable() { + + @Override + public void run() { + + MissionObject mission = getMissionObject(); + SWGObject target = core.objectService.getObject(markObjId); + CreatureObject player = (CreatureObject) mission.getGrandparent(); + + if (target == null) { + player.sendSystemMessage("@mission/mission_generic:player_target_inactive", DisplayType.Broadcast); + cancelLocationUpdates(); + return; + } else if (target.getPlanet().getName() != getSeekerPlanet()) { + player.sendSystemMessage("@mission/mission_generic:target_not_on_planet", DisplayType.Broadcast); + cancelLocationUpdates(); + return; + } else { + WaypointObject missionWp = mission.getAttachedWaypoint(); + + if (missionWp == null) { + player.sendSystemMessage("@mission/mission_generic:target_not_found_1", DisplayType.Broadcast); + cancelLocationUpdates(); + return; + } + missionWp.setPosition(target.getWorldPosition()); + + mission.setAttachedWaypoint(missionWp); + player.sendSystemMessage("@mission/mission_generic:target_location_updated_ground", DisplayType.Broadcast); + } + } + }, 60, 15, TimeUnit.SECONDS); + + setLocationUpdater(updates); + } + } + + public void cancelLocationUpdates() { + getLocationUpdater().cancel(true); + setSeekerActive(false); + setSeekerPlanet(""); + setArakydActive(false); + } + + public Point3D getLastKnownLocation() { return lastKnownLocation; } + + public void setLastKnownLocation(Point3D lastKnownLocation) { this.lastKnownLocation = lastKnownLocation; } + + public long getMarkObjId() { return markObjId; } + + public void setMarkObjId(long markObjId) { this.markObjId = markObjId; } + + public String getLastKnownPlanet() { return lastKnownPlanet; } + + public void setLastKnownPlanet(String lastKnownPlanet) { this.lastKnownPlanet = lastKnownPlanet; } + + public ScheduledFuture getLocationUpdater() { return locationUpdater; } + + public void setLocationUpdater(ScheduledFuture locationUpdater) { this.locationUpdater = locationUpdater; } + + public boolean isSeekerActive() { return seekerActive; } + + public void setSeekerActive(boolean seekerActive) { this.seekerActive = seekerActive; } + + public boolean isArakydActive() { return arakydActive; } + + public void setArakydActive(boolean araykdActive) { this.arakydActive = araykdActive; } + + public String getSeekerPlanet() { return seekerPlanet; } + + public void setSeekerPlanet(String seekerPlanet) { this.seekerPlanet = seekerPlanet; } + +} diff --git a/src/resources/objects/Delta.java b/src/resources/objects/Delta.java index 35ef4299..6e57706e 100644 --- a/src/resources/objects/Delta.java +++ b/src/resources/objects/Delta.java @@ -21,6 +21,7 @@ ******************************************************************************/ package resources.objects; +import java.io.Serializable; import java.nio.ByteBuffer; import java.nio.ByteOrder; @@ -33,12 +34,13 @@ import com.sleepycat.persist.model.Persistent; import resources.common.StringUtilities; @Persistent -public abstract class Delta implements IDelta { +public abstract class Delta implements IDelta, Serializable { + private static final long serialVersionUID = 1L; @NotPersistent - protected final Object objectMutex = new Object(); + protected transient final Object objectMutex = new Object(); @NotPersistent - private static SimpleBufferAllocator bufferPool = new SimpleBufferAllocator(); + private transient static SimpleBufferAllocator bufferPool = new SimpleBufferAllocator(); public Delta() { diff --git a/src/resources/objects/IDelta.java b/src/resources/objects/IDelta.java index cf1d8802..874715b0 100644 --- a/src/resources/objects/IDelta.java +++ b/src/resources/objects/IDelta.java @@ -21,10 +21,12 @@ ******************************************************************************/ package resources.objects; +import java.io.Serializable; + import com.sleepycat.persist.model.Persistent; @Persistent -public interface IDelta { +public interface IDelta { public byte[] getBytes(); diff --git a/src/resources/objects/SWGList.java b/src/resources/objects/SWGList.java index 7471305c..d7d63f68 100644 --- a/src/resources/objects/SWGList.java +++ b/src/resources/objects/SWGList.java @@ -21,6 +21,7 @@ ******************************************************************************/ package resources.objects; +import java.io.Serializable; import java.nio.ByteOrder; import java.util.ArrayList; import java.util.Collection; @@ -43,16 +44,17 @@ import com.sleepycat.persist.model.Persistent; /* A SWGList element MUST implement IDelta, or it will refuse to work with it */ @Persistent -public class SWGList implements List { +public class SWGList implements List, Serializable { + private static final long serialVersionUID = 1L; private List list = new ArrayList(); @NotPersistent - private int updateCounter = 1; + private transient int updateCounter = 1; private ObjectMessageBuilder messageBuilder; private byte viewType; private short updateType; @NotPersistent - protected final Object objectMutex = new Object(); + protected transient final Object objectMutex = new Object(); public SWGList() { } diff --git a/src/resources/objects/SWGMap.java b/src/resources/objects/SWGMap.java index b8f9610d..5e4a28a9 100644 --- a/src/resources/objects/SWGMap.java +++ b/src/resources/objects/SWGMap.java @@ -21,6 +21,7 @@ ******************************************************************************/ package resources.objects; +import java.io.Serializable; import java.nio.ByteOrder; import java.util.ArrayList; import java.util.Collection; @@ -43,16 +44,17 @@ import com.sleepycat.persist.model.Persistent; @SuppressWarnings("unused") @Persistent -public class SWGMap implements Map { +public class SWGMap implements Map, Serializable { + private static final long serialVersionUID = 1L; private Map map = new TreeMap(); @NotPersistent - private int updateCounter = 0; + private transient int updateCounter = 0; private ObjectMessageBuilder messageBuilder; private byte viewType; private short updateType; @NotPersistent - protected final Object objectMutex = new Object(); + protected transient final Object objectMutex = new Object(); public SWGMap() { } diff --git a/src/resources/objects/SWGMultiMap.java b/src/resources/objects/SWGMultiMap.java index 850b55f9..a632c20c 100644 --- a/src/resources/objects/SWGMultiMap.java +++ b/src/resources/objects/SWGMultiMap.java @@ -21,6 +21,7 @@ ******************************************************************************/ package resources.objects; +import java.io.Serializable; import java.nio.ByteOrder; import java.util.ArrayList; import java.util.Collection; @@ -46,16 +47,17 @@ import com.sleepycat.persist.model.Persistent; @SuppressWarnings("unused") @Persistent -public class SWGMultiMap implements Multimap { +public class SWGMultiMap implements Multimap, Serializable { + private static final long serialVersionUID = 1L; private Multimap map = ArrayListMultimap.create(); @NotPersistent - private int updateCounter = 0; + private transient int updateCounter = 0; private ObjectMessageBuilder messageBuilder; private byte viewType; private short updateType; @NotPersistent - protected final Object objectMutex = new Object(); + protected transient final Object objectMutex = new Object(); public SWGMultiMap() { } diff --git a/src/resources/objects/building/BuildingObject.java b/src/resources/objects/building/BuildingObject.java index 5d276fc8..0b8f208b 100644 --- a/src/resources/objects/building/BuildingObject.java +++ b/src/resources/objects/building/BuildingObject.java @@ -21,11 +21,13 @@ ******************************************************************************/ package resources.objects.building; +import java.io.Serializable; import java.util.Vector; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; import main.NGECore; +import resources.objects.cell.CellMessageBuilder; import resources.objects.cell.CellObject; import resources.objects.creature.CreatureObject; @@ -44,12 +46,13 @@ import engine.resources.scene.Point3D; import engine.resources.scene.Quaternion; @Entity(version=6) -public class BuildingObject extends TangibleObject implements IPersistent { +public class BuildingObject extends TangibleObject implements IPersistent, Serializable { + private static final long serialVersionUID = 1L; @NotPersistent - private BuildingMessageBuilder messageBuilder; + private transient BuildingMessageBuilder messageBuilder; @NotPersistent - private Transaction txn; + private transient Transaction txn; private float maintenanceAmount = 0; private int BMR = 0; @@ -262,4 +265,10 @@ public class BuildingObject extends TangibleObject implements IPersistent { return cells; } + @Override + public void initAfterDBLoad() { + super.init(); + messageBuilder = new BuildingMessageBuilder(this); + } + } diff --git a/src/resources/objects/cell/CellObject.java b/src/resources/objects/cell/CellObject.java index 32f1e86b..1c787a13 100644 --- a/src/resources/objects/cell/CellObject.java +++ b/src/resources/objects/cell/CellObject.java @@ -21,10 +21,13 @@ ******************************************************************************/ package resources.objects.cell; +import java.io.Serializable; + import protocol.swg.UpdateCellPermissionMessage; import com.sleepycat.persist.model.NotPersistent; import com.sleepycat.persist.model.Persistent; + import engine.clients.Client; import engine.resources.objects.SWGObject; import engine.resources.scene.Planet; @@ -32,11 +35,12 @@ import engine.resources.scene.Point3D; import engine.resources.scene.Quaternion; @Persistent(version=0) -public class CellObject extends SWGObject { +public class CellObject extends SWGObject implements Serializable { + private static final long serialVersionUID = 1L; private int cellNumber = 0; @NotPersistent - private CellMessageBuilder messageBuilder; + private transient CellMessageBuilder messageBuilder; public CellObject() { super(); @@ -80,5 +84,11 @@ public class CellObject extends SWGObject { } + @Override + public void initAfterDBLoad() { + super.init(); + messageBuilder = new CellMessageBuilder(this); + } + } diff --git a/src/resources/objects/craft/DraftSchematic.java b/src/resources/objects/craft/DraftSchematic.java index 3e47ae31..dfebddf8 100644 --- a/src/resources/objects/craft/DraftSchematic.java +++ b/src/resources/objects/craft/DraftSchematic.java @@ -21,7 +21,12 @@ ******************************************************************************/ package resources.objects.craft; +import java.io.Serializable; + +import resources.objects.building.BuildingMessageBuilder; + import com.sleepycat.persist.model.Persistent; + import engine.clients.Client; import engine.resources.objects.SWGObject; import engine.resources.scene.Planet; @@ -29,9 +34,10 @@ import engine.resources.scene.Point3D; import engine.resources.scene.Quaternion; @Persistent -public class DraftSchematic extends SWGObject { - +public class DraftSchematic extends SWGObject implements Serializable { + private static final long serialVersionUID = 1L; + public DraftSchematic(long objectID, Planet planet, String template, Point3D position, Quaternion orientation){ super(objectID, planet, position, orientation, template); } @@ -42,5 +48,11 @@ public class DraftSchematic extends SWGObject { } + @Override + public void initAfterDBLoad() { + super.init(); + } + + } diff --git a/src/resources/objects/creature/CreatureObject.java b/src/resources/objects/creature/CreatureObject.java index cfd9a60c..8d8f7749 100644 --- a/src/resources/objects/creature/CreatureObject.java +++ b/src/resources/objects/creature/CreatureObject.java @@ -21,6 +21,7 @@ ******************************************************************************/ package resources.objects.creature; +import java.io.Serializable; import java.lang.System; import java.util.ArrayList; import java.util.Collections; @@ -62,23 +63,23 @@ import engine.resources.objects.SWGObject; import engine.resources.scene.Planet; import engine.resources.scene.Point3D; import engine.resources.scene.Quaternion; +import resources.objects.building.BuildingMessageBuilder; import resources.objects.player.PlayerObject; import resources.objects.tangible.TangibleObject; import resources.skills.SkillMod; import services.command.BaseSWGCommand; @Entity(version=9) -public class CreatureObject extends TangibleObject implements IPersistent { +public class CreatureObject extends TangibleObject implements Serializable { - @NotPersistent - private Transaction txn; + private static final long serialVersionUID = 1L; // CREO 1 private int bankCredits = 0; private int cashCredits = 0; private List skills; @NotPersistent - private int skillsUpdateCounter = 0; + private transient int skillsUpdateCounter = 0; // CREO 3 private byte posture = 0; @@ -105,7 +106,7 @@ public class CreatureObject extends TangibleObject implements IPersistent { private SWGList missionCriticalObjects; @NotPersistent - private int missionCriticalObjectsUpdateCounter = 0; + private transient int missionCriticalObjectsUpdateCounter = 0; // CREO6 @@ -130,30 +131,30 @@ public class CreatureObject extends TangibleObject implements IPersistent { private boolean acceptBandflourishes = true; private boolean groupDance = true; @NotPersistent - private CreatureObject performanceWatchee; + private transient CreatureObject performanceWatchee; @NotPersistent - private CreatureObject performanceListenee; + private transient CreatureObject performanceListenee; @NotPersistent - private Vector performanceAudience = new Vector(); + private transient Vector performanceAudience = new Vector(); private int health = 1000; private int action = 300; @NotPersistent - private int HAMListCounter = 0; + private transient int HAMListCounter = 0; private int maxHealth = 1000; private int maxAction = 300; @NotPersistent - private int maxHAMListCounter = 0; + private transient int maxHAMListCounter = 0; private SWGList equipmentList; @NotPersistent - private int equipmentListUpdateCounter = 0; + private transient int equipmentListUpdateCounter = 0; private SWGList buffList = new SWGList(); @NotPersistent - private int buffListUpdateCounter = 0; + private transient int buffListUpdateCounter = 0; private byte difficulty = 0; private SWGList appearanceEquipmentList; @NotPersistent - private int appearanceEquipmentListUpdateCounter = 0; + private transient int appearanceEquipmentListUpdateCounter = 0; private boolean inStealth = false; private boolean radarVisible = true; // radar @@ -161,36 +162,36 @@ public class CreatureObject extends TangibleObject implements IPersistent { // non-baseline vars @NotPersistent - private List duelList = Collections.synchronizedList(new ArrayList()); + private transient List duelList = Collections.synchronizedList(new ArrayList()); @NotPersistent - private CreatureMessageBuilder messageBuilder; + private transient CreatureMessageBuilder messageBuilder; private SWGList dotList = new SWGList(); @NotPersistent - private ScheduledFuture incapTask; + private transient ScheduledFuture incapTask; @NotPersistent - private ScheduledFuture entertainerExperience; + private transient ScheduledFuture entertainerExperience; @NotPersistent - private ScheduledFuture inspirationTick; + private transient ScheduledFuture inspirationTick; @NotPersistent - private ScheduledFuture spectatorTask; + private transient ScheduledFuture spectatorTask; private boolean staticNPC = false; // temp @NotPersistent - private int flourishCount = 0; + private transient int flourishCount = 0; @NotPersistent - private boolean performingEffect; + private transient boolean performingEffect; @NotPersistent - private boolean performingFlourish; + private transient boolean performingFlourish; private int coverCharge; @NotPersistent - private TangibleObject conversingNpc; + private transient TangibleObject conversingNpc; @NotPersistent - private ConcurrentHashMap cooldowns = new ConcurrentHashMap(); + private transient ConcurrentHashMap cooldowns = new ConcurrentHashMap(); @NotPersistent - private long tefTime = System.currentTimeMillis(); + private transient long tefTime = System.currentTimeMillis(); @NotPersistent - private SWGObject useTarget; + private transient SWGObject useTarget; public CreatureObject(long objectID, Planet planet, Point3D position, Quaternion orientation, String Template) { super(objectID, planet, Template, position, orientation); @@ -210,6 +211,12 @@ public class CreatureObject extends TangibleObject implements IPersistent { messageBuilder = new CreatureMessageBuilder(this); } + @Override + public void initAfterDBLoad() { + super.init(); + messageBuilder = new CreatureMessageBuilder(this); + } + private void loadTemplateData() { /*if(getTemplateData().getAttribute("scale") != null) @@ -228,10 +235,6 @@ public class CreatureObject extends TangibleObject implements IPersistent { notifyObservers(messageBuilder.buildCustomNameDelta(customName), true); } - - public Transaction getTransaction() { return txn; } - - public void createTransaction(Environment env) { txn = env.beginTransaction(null, null); } public int getBankCredits() { synchronized(objectMutex) { diff --git a/src/resources/objects/factorycrate/FactoryCrateObject.java b/src/resources/objects/factorycrate/FactoryCrateObject.java index d7b7b7d6..a2cf5f4d 100644 --- a/src/resources/objects/factorycrate/FactoryCrateObject.java +++ b/src/resources/objects/factorycrate/FactoryCrateObject.java @@ -21,11 +21,11 @@ ******************************************************************************/ package resources.objects.factorycrate; +import java.io.Serializable; import java.util.Map; import java.util.Vector; import main.NGECore; - import protocol.swg.SceneCreateObjectByCrc; import protocol.swg.SceneDestroyObject; import protocol.swg.SceneEndBaselines; @@ -41,7 +41,7 @@ import engine.resources.objects.SWGObject; import engine.resources.scene.Planet; import engine.resources.scene.Point3D; import engine.resources.scene.Quaternion; - +import resources.objects.creature.CreatureMessageBuilder; import resources.objects.creature.CreatureObject; import resources.objects.tangible.TangibleObject; @@ -50,8 +50,10 @@ import resources.objects.tangible.TangibleObject; */ @Persistent(version=0) -public class FactoryCrateObject extends TangibleObject { +public class FactoryCrateObject extends TangibleObject implements Serializable { + private static final long serialVersionUID = 1L; + private Vector contents; private byte capacity; private byte contentObjectQuantity; @@ -59,12 +61,19 @@ public class FactoryCrateObject extends TangibleObject { private TangibleObject contentObjectType; @NotPersistent - private FactoryCrateMessageBuilder messageBuilder; + private transient FactoryCrateMessageBuilder messageBuilder; public FactoryCrateObject() { } + @Override + public void initAfterDBLoad() { + super.init(); + messageBuilder = new FactoryCrateMessageBuilder(this); + } + + public FactoryCrateObject(long objectID, Planet planet, String template, Point3D position, Quaternion orientation) { super(objectID, planet, template, position, orientation); this.messageBuilder = new FactoryCrateMessageBuilder(this); diff --git a/src/resources/objects/group/GroupObject.java b/src/resources/objects/group/GroupObject.java index 0f5c4622..561bf7e7 100644 --- a/src/resources/objects/group/GroupObject.java +++ b/src/resources/objects/group/GroupObject.java @@ -21,10 +21,10 @@ ******************************************************************************/ package resources.objects.group; +import java.io.Serializable; import java.util.Vector; import resources.objects.universe.UniverseObject; - import engine.clients.Client; import engine.resources.objects.SWGObject; import engine.resources.scene.Point3D; diff --git a/src/resources/objects/guild/GuildObject.java b/src/resources/objects/guild/GuildObject.java index 5890756b..7306cf99 100644 --- a/src/resources/objects/guild/GuildObject.java +++ b/src/resources/objects/guild/GuildObject.java @@ -21,6 +21,7 @@ ******************************************************************************/ package resources.objects.guild; +import java.io.Serializable; import java.util.HashMap; import java.util.Map; import java.util.TreeMap; @@ -28,7 +29,6 @@ import java.util.TreeMap; import org.apache.mina.core.buffer.IoBuffer; import main.NGECore; - import resources.gcw.CurrentServerGCWZoneHistory; import resources.gcw.CurrentServerGCWZonePercent; import resources.gcw.OtherServerGCWZonePercent; @@ -36,6 +36,7 @@ import resources.guild.Guild; import resources.objects.SWGList; import resources.objects.SWGMap; import resources.objects.SWGMultiMap; +import resources.objects.cell.CellMessageBuilder; import resources.objects.universe.UniverseObject; import services.collections.ServerFirst; @@ -51,16 +52,15 @@ import engine.resources.scene.Point3D; import engine.resources.scene.Quaternion; @Entity(version=1) -public class GuildObject extends UniverseObject implements IPersistent { +public class GuildObject extends UniverseObject implements Serializable { + private static final long serialVersionUID = 1L; protected NGECore core; @NotPersistent - private GuildMessageBuilder messageBuilder = new GuildMessageBuilder(this); + private transient GuildMessageBuilder messageBuilder = new GuildMessageBuilder(this); private Map serverFirst = new HashMap(); private Map> zoneMap = new TreeMap>(); - @NotPersistent - private Transaction txn; private long nextInstanceId = 0; @@ -91,6 +91,13 @@ public class GuildObject extends UniverseObject implements IPersistent { this.core = core; } + @Override + public void initAfterDBLoad() { + super.init(); + messageBuilder = new GuildMessageBuilder(this); + } + + public float getComplexity() { synchronized(objectMutex) { return complexity; @@ -302,12 +309,5 @@ public class GuildObject extends UniverseObject implements IPersistent { } } - public Transaction getTransaction() { - return txn; - } - - public void createTransaction(Environment env) { - txn = env.beginTransaction(null, null); - } } diff --git a/src/resources/objects/harvester/HarvesterObject.java b/src/resources/objects/harvester/HarvesterObject.java index 8964d7e1..93da82cf 100644 --- a/src/resources/objects/harvester/HarvesterObject.java +++ b/src/resources/objects/harvester/HarvesterObject.java @@ -21,6 +21,7 @@ ******************************************************************************/ package resources.objects.harvester; +import java.io.Serializable; import java.util.Vector; import main.NGECore; @@ -32,6 +33,7 @@ import engine.resources.scene.Planet; import engine.resources.scene.Point3D; import engine.resources.scene.Quaternion; import resources.objects.creature.CreatureObject; +import resources.objects.guild.GuildMessageBuilder; import resources.objects.installation.InstallationMessageBuilder; import resources.objects.installation.InstallationObject; import resources.objects.resource.GalacticResource; @@ -42,8 +44,10 @@ import resources.objects.resource.ResourceContainerObject; */ @Persistent(version=0) -public class HarvesterObject extends InstallationObject { +public class HarvesterObject extends InstallationObject implements Serializable { + private static final long serialVersionUID = 1L; + private HarvesterMessageBuilder messageBuilder; private InstallationMessageBuilder installationMessageBuilder; @@ -128,6 +132,13 @@ public class HarvesterObject extends InstallationObject { public int getBER() { return BER; } + + @Override + public void initAfterDBLoad() { + super.init(); + messageBuilder = new HarvesterMessageBuilder(this); + installationMessageBuilder = new InstallationMessageBuilder((InstallationObject)this); + } public void setBER(int baseExtractionRate) { diff --git a/src/resources/objects/installation/InstallationObject.java b/src/resources/objects/installation/InstallationObject.java index 4d78229d..090b985b 100644 --- a/src/resources/objects/installation/InstallationObject.java +++ b/src/resources/objects/installation/InstallationObject.java @@ -21,17 +21,22 @@ ******************************************************************************/ package resources.objects.installation; +import java.io.Serializable; + import com.sleepycat.persist.model.Entity; import engine.clients.Client; import engine.resources.scene.Planet; import engine.resources.scene.Point3D; import engine.resources.scene.Quaternion; +import resources.objects.cell.CellMessageBuilder; import resources.objects.tangible.TangibleObject; @Entity(version=0) -public class InstallationObject extends TangibleObject { +public class InstallationObject extends TangibleObject implements Serializable { + private static final long serialVersionUID = 1L; + public InstallationObject(long objectID, Planet planet, String template, Point3D position, Quaternion orientation){ super(objectID, planet, template, position, orientation); } @@ -40,4 +45,10 @@ public class InstallationObject extends TangibleObject { public void sendBaselines(Client destination) { } + + @Override + public void initAfterDBLoad() { + super.init(); + } + } \ No newline at end of file diff --git a/src/resources/objects/intangible/IntangibleObject.java b/src/resources/objects/intangible/IntangibleObject.java index 23801ed6..a0f4444d 100644 --- a/src/resources/objects/intangible/IntangibleObject.java +++ b/src/resources/objects/intangible/IntangibleObject.java @@ -21,6 +21,10 @@ ******************************************************************************/ package resources.objects.intangible; +import java.io.Serializable; + +import resources.objects.cell.CellMessageBuilder; + import com.sleepycat.persist.model.Persistent; import engine.clients.Client; @@ -30,8 +34,10 @@ import engine.resources.scene.Point3D; import engine.resources.scene.Quaternion; @Persistent(version=0) -public class IntangibleObject extends SWGObject { +public class IntangibleObject extends SWGObject implements Serializable { + private static final long serialVersionUID = 1L; + private int genericInt; public IntangibleObject() { @@ -42,6 +48,11 @@ public class IntangibleObject extends SWGObject { super(objectID, planet, position, orientation, Template); } + @Override + public void initAfterDBLoad() { + super.init(); + } + public int getGenericInt() { synchronized(objectMutex) { return genericInt; diff --git a/src/resources/objects/manufacture/ManufactureSchematicObject.java b/src/resources/objects/manufacture/ManufactureSchematicObject.java index 4ed340ef..38d77857 100644 --- a/src/resources/objects/manufacture/ManufactureSchematicObject.java +++ b/src/resources/objects/manufacture/ManufactureSchematicObject.java @@ -22,8 +22,13 @@ package resources.objects.manufacture; +import java.io.Serializable; + +import resources.objects.cell.CellMessageBuilder; import resources.objects.intangible.IntangibleObject; + import com.sleepycat.persist.model.Persistent; + import engine.resources.scene.Planet; import engine.resources.scene.Point3D; import engine.resources.scene.Quaternion; @@ -34,8 +39,9 @@ import engine.resources.scene.Quaternion; */ @Persistent(version=0) -public class ManufactureSchematicObject extends IntangibleObject{ +public class ManufactureSchematicObject extends IntangibleObject implements Serializable { + private static final long serialVersionUID = 1L; //@NotPersistent //private ManufactureSchematicMessageBuilder messageBuilder; @@ -44,4 +50,11 @@ public class ManufactureSchematicObject extends IntangibleObject{ //messageBuilder = new ManufactureSchematicMessageBuilder(this); } + @Override + public void initAfterDBLoad() { + super.init(); + //messageBuilder = new ManufactureSchematicMessageBuilder(this); + } + + } diff --git a/src/resources/objects/mission/MissionObject.java b/src/resources/objects/mission/MissionObject.java index 48f573f2..67d9cee4 100644 --- a/src/resources/objects/mission/MissionObject.java +++ b/src/resources/objects/mission/MissionObject.java @@ -21,12 +21,15 @@ ******************************************************************************/ package resources.objects.mission; +import java.io.Serializable; + import com.sleepycat.je.Environment; import com.sleepycat.je.Transaction; import com.sleepycat.persist.model.NotPersistent; import com.sleepycat.persist.model.Persistent; import resources.common.BountyListItem; +import resources.objects.cell.CellMessageBuilder; import resources.objects.intangible.IntangibleObject; import resources.objects.waypoint.WaypointObject; import services.mission.MissionObjective; @@ -37,8 +40,9 @@ import engine.resources.scene.Point3D; import engine.resources.scene.Quaternion; @Persistent(version=1) -public class MissionObject extends IntangibleObject implements IPersistent { - +public class MissionObject extends IntangibleObject implements Serializable { + + private static final long serialVersionUID = 1L; private Point3D destination; private Point3D startLocation; private String startPlanet = ""; @@ -60,11 +64,8 @@ public class MissionObject extends IntangibleObject implements IPersistent { private long bountyObjId; @NotPersistent - MissionMessageBuilder messageBuilder = new MissionMessageBuilder(this); - - @NotPersistent - private Transaction txn; - + private transient MissionMessageBuilder messageBuilder = new MissionMessageBuilder(this); + public MissionObject() { super(); } @@ -78,6 +79,12 @@ public class MissionObject extends IntangibleObject implements IPersistent { return destinationPlanet; } } + + @Override + public void initAfterDBLoad() { + super.init(); + messageBuilder = new MissionMessageBuilder(this); + } public int getMissionLevel() { synchronized(objectMutex) { @@ -306,14 +313,6 @@ public class MissionObject extends IntangibleObject implements IPersistent { this.bountyObjId = bountyObjId; } - public Transaction getTransaction() { - return txn; - } - - public void createTransaction(Environment env) { - txn = env.beginTransaction(null, null); - } - @Override public void sendBaselines(Client destination) { diff --git a/src/resources/objects/player/PlayerObject.java b/src/resources/objects/player/PlayerObject.java index bcbc3b21..cc1d4cd9 100644 --- a/src/resources/objects/player/PlayerObject.java +++ b/src/resources/objects/player/PlayerObject.java @@ -21,6 +21,7 @@ ******************************************************************************/ package resources.objects.player; +import java.io.Serializable; import java.util.ArrayList; import java.util.BitSet; import java.util.HashMap; @@ -32,6 +33,7 @@ import resources.objects.intangible.IntangibleObject; import resources.objects.resource.ResourceContainerObject; import resources.objects.tool.SurveyTool; import resources.objects.waypoint.WaypointObject; +import resources.objects.cell.CellMessageBuilder; import resources.objects.creature.CreatureObject; import com.sleepycat.persist.model.NotPersistent; @@ -45,8 +47,9 @@ import engine.resources.scene.Point3D; import engine.resources.scene.Quaternion; @Persistent(version=13) -public class PlayerObject extends IntangibleObject { +public class PlayerObject extends IntangibleObject implements Serializable { + private static final long serialVersionUID = 1L; // PLAY 3 private String title; @@ -71,11 +74,11 @@ public class PlayerObject extends IntangibleObject { private Map xpList = new HashMap(); @NotPersistent - private int xpListUpdateCounter = 0; + private transient int xpListUpdateCounter = 0; private List waypoints = new ArrayList(); @NotPersistent - private int waypointListUpdateCounter = 0; + private transient int waypointListUpdateCounter = 0; private int currentForcePower = 0; // unused in NGE private int maxForcePower = 0; // unused in NGE @@ -85,7 +88,7 @@ public class PlayerObject extends IntangibleObject { private List questJournal = new ArrayList(); @NotPersistent - private int questJournalUpdateCounter = 0; + private transient int questJournalUpdateCounter = 0; private String professionWheelPosition; @@ -97,17 +100,17 @@ public class PlayerObject extends IntangibleObject { private List draftSchematicList = new ArrayList(); @NotPersistent - private int draftSchematicListUpdateCounter = 0; + private transient int draftSchematicListUpdateCounter = 0; private int experimentationPoints = 0; private int accomplishmentCounter = 0; private List friendList = new ArrayList(); @NotPersistent - private int friendListUpdateCounter = 0; + private transient int friendListUpdateCounter = 0; private List ignoreList = new ArrayList(); @NotPersistent - private int ignoreListUpdateCounter = 0; + private transient int ignoreListUpdateCounter = 0; private int languageId = 0; // unused in NGE private int currentStomach = 0; // unused in NGE @@ -129,10 +132,10 @@ public class PlayerObject extends IntangibleObject { private int lotsRemaining = 10; @NotPersistent - private PlayerMessageBuilder messageBuilder; + private transient PlayerMessageBuilder messageBuilder; @NotPersistent - private long lastPlayTimeUpdate = System.currentTimeMillis(); + private transient long lastPlayTimeUpdate = System.currentTimeMillis(); private Map factionStandingMap = new TreeMap(); @@ -145,7 +148,7 @@ public class PlayerObject extends IntangibleObject { private List chatChannels = new ArrayList(); @NotPersistent - private boolean callingCompanion = false; + private transient boolean callingCompanion = false; public PlayerObject() { super(); @@ -156,6 +159,12 @@ public class PlayerObject extends IntangibleObject { super(objectID, planet, new Point3D(0, 0, 0), new Quaternion(1, 0, 0, 0), "object/player/shared_player.iff"); messageBuilder = new PlayerMessageBuilder(this); } + + @Override + public void initAfterDBLoad() { + super.init(); + messageBuilder = new PlayerMessageBuilder(this); + } public String getTitle() { synchronized(objectMutex) { diff --git a/src/resources/objects/resource/GalacticResource.java b/src/resources/objects/resource/GalacticResource.java index 9f23a171..01f0ef81 100644 --- a/src/resources/objects/resource/GalacticResource.java +++ b/src/resources/objects/resource/GalacticResource.java @@ -21,6 +21,7 @@ ******************************************************************************/ package resources.objects.resource; +import java.io.Serializable; import java.util.List; import java.util.Random; import java.util.Vector; @@ -28,6 +29,7 @@ import java.util.Vector; import main.NGECore; import protocol.swg.SurveyMapUpdateMessage; import resources.objects.creature.CreatureObject; +import resources.objects.player.PlayerMessageBuilder; import resources.objects.player.PlayerObject; import resources.objects.waypoint.WaypointObject; @@ -48,10 +50,9 @@ import engine.resources.scene.Quaternion; */ @Entity(version=0) -public class GalacticResource extends SWGObject implements IPersistent { +public class GalacticResource extends SWGObject implements Serializable { - @NotPersistent - private Transaction txn; + private static final long serialVersionUID = 1L; private String name; private String fileName; @@ -63,30 +64,30 @@ public class GalacticResource extends SWGObject implements IPersistent { @NotPersistent - public static final int INT_COLDRESISTANCE = 0; + public transient static final int INT_COLDRESISTANCE = 0; @NotPersistent - public static final int INT_CONDUCTIVITY = 1; + public transient static final int INT_CONDUCTIVITY = 1; @NotPersistent - public static final int INT_DECAYRESISTANCE = 2; + public transient static final int INT_DECAYRESISTANCE = 2; @NotPersistent - public static final int INT_HEATRESISTANCE = 3; + public transient static final int INT_HEATRESISTANCE = 3; @NotPersistent - public static final int INT_MALLEABILITY = 4; + public transient static final int INT_MALLEABILITY = 4; @NotPersistent - public static final int INT_SHOCKRESISTANCE = 5; + public transient static final int INT_SHOCKRESISTANCE = 5; @NotPersistent - public static final int INT_UNITTOUGHNESS = 6; + public transient static final int INT_UNITTOUGHNESS = 6; @NotPersistent - public static final int INT_ENTANGLERESISTANCE = 7; + public transient static final int INT_ENTANGLERESISTANCE = 7; @NotPersistent - public static final int INT_POTENTIALENERGY = 8; + public transient static final int INT_POTENTIALENERGY = 8; @NotPersistent - public static final int INT_OVERALLQUALITY = 9; + public transient static final int INT_OVERALLQUALITY = 9; @NotPersistent - public static final int INT_FLAVOR = 10; + public transient static final int INT_FLAVOR = 10; @NotPersistent - public static final String[] statNamesLookup = {"Cold Resistance", + public transient static final String[] statNamesLookup = {"Cold Resistance", "Conductivity", "Decay Resistance", "Heat Resistance", @@ -117,22 +118,22 @@ public class GalacticResource extends SWGObject implements IPersistent { short[] resourceStats = new short[11]; @NotPersistent - private static int RES_CAT_HI = 1; // Up to 99%, easy to find spots over 90% + private transient static int RES_CAT_HI = 1; // Up to 99%, easy to find spots over 90% @NotPersistent - private static int RES_CAT_MID = 2; // Up to 90%, often have to settle at around 80% + private transient static int RES_CAT_MID = 2; // Up to 90%, often have to settle at around 80% @NotPersistent - private static int RES_CAT_LO = 3; // Up to 70%, often have to settle around 60% + private transient static int RES_CAT_LO = 3; // Up to 70%, often have to settle around 60% @NotPersistent - private static int RES_CAT_CRE = 4; // Creature resource + private transient static int RES_CAT_CRE = 4; // Creature resource @NotPersistent // Direct Persistence Layer entity reference restriction - private ResourceRoot resourceRoot; + private transient ResourceRoot resourceRoot; private int resourceRootID; // This is for re-referencing the resourceRoot in the reloaded resourceRoot collection // due to the DPL entity reference restriction @NotPersistent - private double minDist = 99999.0; + private transient double minDist = 99999.0; public GalacticResource(){ @@ -148,6 +149,10 @@ public class GalacticResource extends SWGObject implements IPersistent { this.id = id; } + @Override + public void initAfterDBLoad() { + } + public GalacticResource(String name, String fileName, String category){ this.name = name; this.fileName = fileName; @@ -633,13 +638,6 @@ public class GalacticResource extends SWGObject implements IPersistent { "zau"}; - @Override - public void createTransaction(Environment env) { txn = env.beginTransaction(null, null);} - - - @Override - public Transaction getTransaction() { return txn; } - @Override public void sendBaselines(Client arg0) { } diff --git a/src/resources/objects/resource/PlanetDeposits.java b/src/resources/objects/resource/PlanetDeposits.java index 712ec89b..9daea331 100644 --- a/src/resources/objects/resource/PlanetDeposits.java +++ b/src/resources/objects/resource/PlanetDeposits.java @@ -1,12 +1,14 @@ package resources.objects.resource; +import java.io.Serializable; import java.util.List; import com.sleepycat.persist.model.Persistent; @Persistent(version=0) -public class PlanetDeposits { +public class PlanetDeposits implements Serializable { + private static final long serialVersionUID = 1L; private int planetId; private List depositList; diff --git a/src/resources/objects/resource/ResourceContainerObject.java b/src/resources/objects/resource/ResourceContainerObject.java index c5b84a9f..55642224 100644 --- a/src/resources/objects/resource/ResourceContainerObject.java +++ b/src/resources/objects/resource/ResourceContainerObject.java @@ -22,6 +22,8 @@ package resources.objects.resource; +import java.io.Serializable; + import main.NGECore; import com.sleepycat.persist.model.NotPersistent; @@ -33,6 +35,7 @@ import engine.resources.scene.Planet; import engine.resources.scene.Point3D; import engine.resources.scene.Quaternion; import resources.objects.creature.CreatureObject; +import resources.objects.player.PlayerMessageBuilder; import resources.objects.tangible.TangibleObject; /** @@ -40,8 +43,9 @@ import resources.objects.tangible.TangibleObject; */ @Persistent(version=0) -public class ResourceContainerObject extends TangibleObject { +public class ResourceContainerObject extends TangibleObject implements Serializable { + private static final long serialVersionUID = 1L; // Unique ID private long containerID; @@ -131,20 +135,27 @@ public class ResourceContainerObject extends TangibleObject { */ @NotPersistent - public static int maximalStackCapacity = 100000; + public transient static int maximalStackCapacity = 100000; @NotPersistent - private ResourceContainerMessageBuilder messageBuilder; + private transient ResourceContainerMessageBuilder messageBuilder; public ResourceContainerObject(){ } + public ResourceContainerObject(long objectID, Planet planet, String template, Point3D position, Quaternion orientation){ super(objectID, planet, template, position, orientation); messageBuilder = new ResourceContainerMessageBuilder(this); this.setAttachment("radial_filename", "resourceContainer"); - } + } + + @Override + public void initAfterDBLoad() { + super.init(); + messageBuilder = new ResourceContainerMessageBuilder(this); + } public void initializeStats(GalacticResource resource){ this.setResourceName(resource.getName()); diff --git a/src/resources/objects/resource/ResourceDeposit.java b/src/resources/objects/resource/ResourceDeposit.java index 9a6572fc..b3772f52 100644 --- a/src/resources/objects/resource/ResourceDeposit.java +++ b/src/resources/objects/resource/ResourceDeposit.java @@ -1,5 +1,7 @@ package resources.objects.resource; +import java.io.Serializable; + import com.sleepycat.persist.model.Persistent; /** @@ -7,7 +9,9 @@ import com.sleepycat.persist.model.Persistent; */ @Persistent(version=0) -public class ResourceDeposit { +public class ResourceDeposit implements Serializable { + + private static final long serialVersionUID = 1L; private float spawnCoordsX; private float spawnCoordsZ; private float spawnRadius; diff --git a/src/resources/objects/resource/ResourceRoot.java b/src/resources/objects/resource/ResourceRoot.java index 34bba280..31d558da 100644 --- a/src/resources/objects/resource/ResourceRoot.java +++ b/src/resources/objects/resource/ResourceRoot.java @@ -21,6 +21,8 @@ ******************************************************************************/ package resources.objects.resource; +import java.io.Serializable; + import com.sleepycat.je.Environment; import com.sleepycat.je.Transaction; import com.sleepycat.persist.model.Entity; @@ -32,8 +34,9 @@ import com.sleepycat.persist.model.PrimaryKey; */ @Entity(version=0) -public class ResourceRoot { +public class ResourceRoot implements Serializable { + private static final long serialVersionUID = 1L; // Publish 15: // - Total: 61, Minimum pool: 15, Random pool: 24 (3 was removed), Fixed pool: 22. @@ -84,7 +87,7 @@ public class ResourceRoot { // All 38 Organic types for each planet @NotPersistent - private Transaction txn; + private transient Transaction txn; private static int highestID = 0; diff --git a/src/resources/objects/ship/ShipObject.java b/src/resources/objects/ship/ShipObject.java index 62d4d6a4..9bb96682 100644 --- a/src/resources/objects/ship/ShipObject.java +++ b/src/resources/objects/ship/ShipObject.java @@ -21,11 +21,21 @@ ******************************************************************************/ package resources.objects.ship; +import java.io.Serializable; + import com.sleepycat.persist.model.Persistent; +import resources.objects.resource.ResourceContainerMessageBuilder; import resources.objects.tangible.TangibleObject; @Persistent(version=0) -public class ShipObject extends TangibleObject { +public class ShipObject extends TangibleObject implements Serializable { + + private static final long serialVersionUID = 1L; + + @Override + public void initAfterDBLoad() { + super.init(); + } } diff --git a/src/resources/objects/staticobject/StaticObject.java b/src/resources/objects/staticobject/StaticObject.java index 53297b00..ff662fdc 100644 --- a/src/resources/objects/staticobject/StaticObject.java +++ b/src/resources/objects/staticobject/StaticObject.java @@ -21,6 +21,10 @@ ******************************************************************************/ package resources.objects.staticobject; +import java.io.Serializable; + +import resources.objects.resource.ResourceContainerMessageBuilder; + import com.sleepycat.persist.model.NotPersistent; import com.sleepycat.persist.model.Persistent; @@ -31,10 +35,11 @@ import engine.resources.scene.Point3D; import engine.resources.scene.Quaternion; @Persistent(version=0) -public class StaticObject extends SWGObject { +public class StaticObject extends SWGObject implements Serializable { + private static final long serialVersionUID = 1L; @NotPersistent - private StaticMessageBuilder messageBuilder; + private transient StaticMessageBuilder messageBuilder; public StaticObject() { super(); @@ -60,4 +65,11 @@ public class StaticObject extends SWGObject { } + + @Override + public void initAfterDBLoad() { + super.init(); + messageBuilder = new StaticMessageBuilder(this); + } + } diff --git a/src/resources/objects/tangible/TangibleObject.java b/src/resources/objects/tangible/TangibleObject.java index a06dfcaf..53fa78e7 100644 --- a/src/resources/objects/tangible/TangibleObject.java +++ b/src/resources/objects/tangible/TangibleObject.java @@ -22,6 +22,7 @@ package resources.objects.tangible; import java.io.ByteArrayOutputStream; +import java.io.Serializable; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -42,6 +43,7 @@ import resources.common.RGB; import resources.datatables.Options; import resources.loot.LootGroup; import resources.objects.creature.CreatureObject; +import resources.objects.staticobject.StaticMessageBuilder; import resources.visitors.IDManagerVisitor; import com.sleepycat.persist.model.NotPersistent; @@ -54,9 +56,10 @@ import engine.resources.scene.Planet; import engine.resources.scene.Point3D; import engine.resources.scene.Quaternion; -@Persistent(version=13) -public class TangibleObject extends SWGObject { +@Persistent(version=12) +public class TangibleObject extends SWGObject implements Serializable { + private static final long serialVersionUID = 1L; // TODO: Thread safety protected int incapTimer = 10; @@ -72,9 +75,9 @@ public class TangibleObject extends SWGObject { protected String faction = ""; // Says you're "Imperial Special Forces" if it's 0 for some reason protected int factionStatus = 0; @NotPersistent - private Vector defendersList = new Vector(); // unused in packets but useful for the server + private transient Vector defendersList = new Vector(); // unused in packets but useful for the server @NotPersistent - private TangibleMessageBuilder messageBuilder; + private transient TangibleMessageBuilder messageBuilder; private int respawnTime = 0; private Point3D spawnCoordinates = new Point3D(0, 0, 0); @@ -83,13 +86,13 @@ public class TangibleObject extends SWGObject { private List lootGroups = new ArrayList(); @NotPersistent - private boolean looted = false; // These 4 should not need to be persisted, since a looted corpse will get wiped with server restart + private transient boolean looted = false; // These 4 should not need to be persisted, since a looted corpse will get wiped with server restart @NotPersistent - private boolean lootLock = false; + private transient boolean lootLock = false; @NotPersistent - private boolean creditRelieved = false; + private transient boolean creditRelieved = false; @NotPersistent - private boolean lootItem = false; + private transient boolean lootItem = false; private boolean stackable = false; private int stackCount = 1; @@ -101,7 +104,7 @@ public class TangibleObject extends SWGObject { private String serialNumber; @NotPersistent - private TangibleObject killer = null; + private transient TangibleObject killer = null; public TangibleObject(long objectID, Planet planet, String template) { super(objectID, planet, new Point3D(0, 0, 0), new Quaternion(1, 0, 1, 0), template); @@ -121,6 +124,12 @@ public class TangibleObject extends SWGObject { messageBuilder = new TangibleMessageBuilder(this); } + @Override + public void initAfterDBLoad() { + super.init(); + messageBuilder = new TangibleMessageBuilder(this); + } + public void setCustomName2(String customName) { setCustomName(customName); diff --git a/src/resources/objects/tool/SurveyTool.java b/src/resources/objects/tool/SurveyTool.java index 90dfbc18..ab557446 100644 --- a/src/resources/objects/tool/SurveyTool.java +++ b/src/resources/objects/tool/SurveyTool.java @@ -21,6 +21,7 @@ ******************************************************************************/ package resources.objects.tool; +import java.io.Serializable; import java.util.Vector; import main.NGECore; @@ -34,6 +35,7 @@ import engine.resources.scene.Quaternion; import resources.objects.creature.CreatureObject; import resources.objects.resource.GalacticResource; import resources.objects.resource.ResourceConcentration; +import resources.objects.tangible.TangibleMessageBuilder; import resources.objects.tangible.TangibleObject; /** @@ -41,8 +43,9 @@ import resources.objects.tangible.TangibleObject; */ @Persistent(version=0) -public class SurveyTool extends TangibleObject{ +public class SurveyTool extends TangibleObject implements Serializable { + private static final long serialVersionUID = 1L; private byte toolType=0; private long surveyResourceID; private long userID=0; @@ -50,25 +53,25 @@ public class SurveyTool extends TangibleObject{ private byte SurveyRangeSetting=0; @NotPersistent - private String surveyEffectString=""; + private transient String surveyEffectString=""; @NotPersistent - private String sampleEffectString=""; + private transient String sampleEffectString=""; @NotPersistent - private boolean currentlySurveying=false; + private transient boolean currentlySurveying=false; @NotPersistent - private boolean currentlySampling=false; + private transient boolean currentlySampling=false; @NotPersistent - private boolean currentlyCoolingDown=false; + private transient boolean currentlyCoolingDown=false; @NotPersistent - private boolean exceptionalState=false; + private transient boolean exceptionalState=false; @NotPersistent - private boolean recoveryMode=false; + private transient boolean recoveryMode=false; @NotPersistent - private Long lastSurveyTime=0L; + private transient Long lastSurveyTime=0L; @NotPersistent - private Long lastSampleTime=0L; + private transient Long lastSampleTime=0L; @NotPersistent - private Long recoveryTime=10L; + private transient Long recoveryTime=10L; public static byte MineralSurveyDevice = 1; public static byte ChemicalSurveyDevice = 2; @@ -84,6 +87,12 @@ public class SurveyTool extends TangibleObject{ this.exceptionalState = false; } + @Override + public void initAfterDBLoad() { + super.init(); + this.exceptionalState = false; + } + public SurveyTool(long objectID, Planet planet, String template, Point3D position, Quaternion orientation){ super(objectID, planet, template, position, orientation); surveyEffectString = ""; diff --git a/src/resources/objects/universe/UniverseObject.java b/src/resources/objects/universe/UniverseObject.java index 723d5a1e..7502266a 100644 --- a/src/resources/objects/universe/UniverseObject.java +++ b/src/resources/objects/universe/UniverseObject.java @@ -21,6 +21,10 @@ ******************************************************************************/ package resources.objects.universe; +import java.io.Serializable; + +import resources.objects.tangible.TangibleMessageBuilder; + import com.sleepycat.persist.model.Persistent; import engine.clients.Client; @@ -30,8 +34,10 @@ import engine.resources.scene.Point3D; import engine.resources.scene.Quaternion; @Persistent(version=0) -public class UniverseObject extends SWGObject { +public class UniverseObject extends SWGObject implements Serializable { + private static final long serialVersionUID = 1L; + public UniverseObject(long objectID, Planet planet, Point3D position, Quaternion orientation, String Template) { super(objectID, planet, position, orientation, Template); } @@ -39,6 +45,11 @@ public class UniverseObject extends SWGObject { public UniverseObject() { super(); } + + @Override + public void initAfterDBLoad() { + super.init(); + } @Override public void sendBaselines(Client arg0) { diff --git a/src/resources/objects/waypoint/WaypointObject.java b/src/resources/objects/waypoint/WaypointObject.java index 32d73e1b..15f2f00e 100644 --- a/src/resources/objects/waypoint/WaypointObject.java +++ b/src/resources/objects/waypoint/WaypointObject.java @@ -21,7 +21,10 @@ ******************************************************************************/ package resources.objects.waypoint; +import java.io.Serializable; + import resources.objects.intangible.IntangibleObject; +import resources.objects.tangible.TangibleMessageBuilder; import com.sleepycat.persist.model.Persistent; @@ -31,8 +34,10 @@ import engine.resources.scene.Point3D; import engine.resources.scene.Quaternion; @Persistent(version=0) -public class WaypointObject extends IntangibleObject { +public class WaypointObject extends IntangibleObject implements Serializable { + private static final long serialVersionUID = 1L; + private int cellId; // ??? private long locationNetworkId; private int planetCRC; @@ -54,6 +59,11 @@ public class WaypointObject extends IntangibleObject { super(objectID, planet, position, new Quaternion(0, 0, 0, 1), "object/waypoint/shared_waypoint.iff"); } + @Override + public void initAfterDBLoad() { + super.init(); + } + public int getCellId() { synchronized(objectMutex) { return cellId; diff --git a/src/resources/objects/weapon/WeaponObject.java b/src/resources/objects/weapon/WeaponObject.java index 2d0fa6ba..98acf7ea 100644 --- a/src/resources/objects/weapon/WeaponObject.java +++ b/src/resources/objects/weapon/WeaponObject.java @@ -21,7 +21,10 @@ ******************************************************************************/ package resources.objects.weapon; +import java.io.Serializable; + import resources.datatables.WeaponType; +import resources.objects.tangible.TangibleMessageBuilder; import resources.objects.tangible.TangibleObject; import com.sleepycat.persist.model.NotPersistent; @@ -33,12 +36,14 @@ import engine.resources.scene.Point3D; import engine.resources.scene.Quaternion; @Persistent(version=1) -public class WeaponObject extends TangibleObject { +public class WeaponObject extends TangibleObject implements Serializable { + private static final long serialVersionUID = 1L; + // TODO: Thread safety @NotPersistent - private WeaponMessageBuilder messageBuilder; + private transient WeaponMessageBuilder messageBuilder; public WeaponObject(long objectID, Planet planet, String template) { super(objectID, planet, template, new Point3D(0, 0, 0), new Quaternion(1, 0, 1, 0)); @@ -53,12 +58,17 @@ public class WeaponObject extends TangibleObject { if (this.getClass().getSimpleName().equals("WeaponObject")) setIntAttribute("volume", 1); setStringAttribute("cat_wpn_damage.damage", "0-0"); } - public WeaponObject() { super(); messageBuilder = new WeaponMessageBuilder(this); } + + @Override + public void initAfterDBLoad() { + super.init(); + messageBuilder = new WeaponMessageBuilder(this); + } public int getIncapTimer() { return incapTimer; diff --git a/src/resources/skills/SkillMod.java b/src/resources/skills/SkillMod.java index 2bce0b23..c3cbbbfe 100644 --- a/src/resources/skills/SkillMod.java +++ b/src/resources/skills/SkillMod.java @@ -21,6 +21,8 @@ ******************************************************************************/ package resources.skills; +import java.io.Serializable; + import org.apache.mina.core.buffer.IoBuffer; import resources.objects.Delta; @@ -28,8 +30,10 @@ import resources.objects.Delta; import com.sleepycat.persist.model.Persistent; @Persistent(version=0) -public class SkillMod extends Delta { +public class SkillMod extends Delta implements Serializable { + private static final long serialVersionUID = 1L; + private int base; private int modifier; diff --git a/src/services/CharacterService.java b/src/services/CharacterService.java index a3af573a..55fd1de3 100644 --- a/src/services/CharacterService.java +++ b/src/services/CharacterService.java @@ -269,10 +269,7 @@ public class CharacterService implements INetworkDispatch { core.skillModService.addSkillMod(object, "language_basic_speak", 100); core.skillModService.addSkillMod(object, "creature_harvesting", 25); core.skillModService.addSkillMod(object, "language_wookiee_comprehend", 100); - - - object.createTransaction(core.getCreatureODB().getEnvironment()); - + PlayerObject player = (PlayerObject) core.objectService.createObject("object/player/shared_player.iff", object.getPlanet()); object._add(player); core.skillService.addSkill(object, "species_" + object.getStfName()); @@ -334,9 +331,7 @@ public class CharacterService implements INetworkDispatch { createStarterClothing(object, sharedRaceTemplate, clientCreateCharacter.getStarterProfession()); //core.scriptService.callScript("scripts/", "demo", "CreateStartingCharacter", core, object); - core.getCreatureODB().put(object, Long.class, CreatureObject.class, object.getTransaction()); - // might not need to commit transaction but better safe than sorry - object.getTransaction().commitSync(); + core.getSWGObjectODB().put(object.getObjectID(), object); PreparedStatement ps = databaseConnection.preparedStatement("INSERT INTO characters (id, \"firstName\", \"lastName\", \"accountId\", \"galaxyId\", \"statusId\", appearance, gmflag) VALUES (?, ?, ?, ?, ?, ?, ?, ?)"); ps.setLong(1, object.getObjectID()); diff --git a/src/services/ConnectionService.java b/src/services/ConnectionService.java index c27423cd..b5e5e1e7 100644 --- a/src/services/ConnectionService.java +++ b/src/services/ConnectionService.java @@ -270,7 +270,7 @@ public class ConnectionService implements INetworkDispatch { } }*/ - core.missionService.getBountyList().remove(core.getBountiesODB().get(object.getObjectId(), Long.class, BountyListItem.class)); + core.missionService.getBountyList().remove(core.getBountiesODB().get(object.getObjectId())); ghost.toggleFlag(PlayerFlags.LD); @@ -283,9 +283,7 @@ public class ConnectionService implements INetworkDispatch { schedulers.clear(); core.playerService.getSchedulers().remove(object.getObjectID()); - object.createTransaction(core.getCreatureODB().getEnvironment()); - core.getCreatureODB().put(object, Long.class, CreatureObject.class, object.getTransaction()); - object.getTransaction().commitSync(); + core.getSWGObjectODB().put(object.getObjectID(), object); core.objectService.destroyObject(object); } diff --git a/src/services/DevService.java b/src/services/DevService.java index e2bd4390..270587d7 100644 --- a/src/services/DevService.java +++ b/src/services/DevService.java @@ -91,6 +91,7 @@ public class DevService implements INetworkDispatch { if(creature.getClient().isGM()) suiOptions.put((long) 120, "House Deeds"); if(creature.getClient().isGM()) suiOptions.put((long) 125, "Crafting Tools"); if(creature.getClient().isGM()) suiOptions.put((long) 130, "Vehicle Deeds"); + if(creature.getClient().isGM()) suiOptions.put((long) 121, "Sandbox City"); break; case 3: // [Items] Weapons @@ -1176,6 +1177,10 @@ public class DevService implements INetworkDispatch { inventory.add(deed); return; + + case 121: + NGECore.getInstance().playerCityService.buildSandboxTestCity(player); + case 125: TangibleObject genericCraftingTool = (TangibleObject) core.objectService.createObject("object/tangible/crafting/station/shared_generic_tool.iff", planet); genericCraftingTool.setCustomName("Generic Crafting Tool"); diff --git a/src/services/LoginService.java b/src/services/LoginService.java index 374400ef..5f72c715 100644 --- a/src/services/LoginService.java +++ b/src/services/LoginService.java @@ -206,7 +206,7 @@ public class LoginService implements INetworkDispatch{ core.objectService.destroyObject(object); } - core.getCreatureODB().delete(new Long(packet.getcharId()), Long.class, CreatureObject.class); + core.getSWGObjectODB().remove(object.getObjectID()); DeleteCharacterReplyMessage reply = new DeleteCharacterReplyMessage(0); session.write(reply.serialize()); } diff --git a/src/services/PlayerService.java b/src/services/PlayerService.java index f4cc8884..8cc06788 100644 --- a/src/services/PlayerService.java +++ b/src/services/PlayerService.java @@ -1282,25 +1282,51 @@ public class PlayerService implements INetworkDispatch { } public void sendSetBountyWindow(final CreatureObject victim, final CreatureObject attacker) { - SUIWindow bountyWindow = core.suiService.createInputBox(InputBoxType.INPUT_BOX_OK_CANCEL, "@bounty_hunter:setbounty_title", "@bounty_hunter:setbounty_prompt1 " + attacker.getCustomName() + "?" + "\n@bounty_hunter:setbounty_prompt2 " + victim.getBankCredits(), - victim, null, (float) 10, new SUICallback() { + SUIWindow bountyWindow = core.suiService.createInputBox(InputBoxType.INPUT_BOX_OK_CANCEL, "@bounty_hunter:setbounty_title", "@bounty_hunter:setbounty_prompt1 " + attacker.getCustomName() + "?" + "\n@bounty_hunter:setbounty_prompt2 " + + String.valueOf(victim.getBankCredits() + victim.getCashCredits()), victim, null, (float) 10, new SUICallback() { @Override public void process(SWGObject owner, int eventType, Vector returnList) { if (eventType == 0 && returnList.get(0) != null) { int bounty = Integer.parseInt(returnList.get(0)); + int totalFunds = victim.getBankCredits() + victim.getCashCredits(); - if (bounty > victim.getBankCredits()) + if (bounty > totalFunds) { + victim.sendSystemMessage("@bounty_hunter:setbounty_too_much", DisplayType.Broadcast); + sendSetBountyWindow(victim, attacker); return; - - if (!core.missionService.addToExistingBounty(attacker, bounty)) - core.missionService.createNewBounty(attacker, bounty); - - victim.setBankCredits(victim.getBankCredits() - bounty); + } + + if (bounty < 20000) { + victim.sendSystemMessage("@bounty_hunter:setbounty_too_little", DisplayType.Broadcast); + sendSetBountyWindow(victim, attacker); + return; + } else if (bounty > 1000000) { + victim.sendSystemMessage("@bounty_hunter:setbounty_cap", DisplayType.Broadcast); + bounty = 1000000; + } + + // Try removing bounty amount from the bank first then cash. Remove amount accordingly if bank/cash is less than placed bounty. + if (bounty > victim.getBankCredits()) { + int difference = bounty - victim.getBankCredits(); + + victim.setCashCredits(victim.getCashCredits() - difference); + victim.setBankCredits(0); + } else if (bounty > victim.getCashCredits()) { + int difference = bounty - victim.getCashCredits(); + + victim.setBankCredits(victim.getBankCredits() - difference); + victim.setCashCredits(0); + } else { victim.setBankCredits(victim.getBankCredits() - bounty); } + + if (!core.missionService.addToExistingBounty(attacker.getObjectId(), victim.getObjectId(), bounty)) + core.missionService.createNewBounty(attacker, victim.getObjectId(), bounty); } } }); + bountyWindow.setProperty("txtInput:NumericInteger", "true"); + bountyWindow.setProperty("txtInput:MaxLength", "7"); core.suiService.openSUIWindow(bountyWindow); } diff --git a/src/services/SimulationService.java b/src/services/SimulationService.java index 0b941eb6..ee8bfa50 100644 --- a/src/services/SimulationService.java +++ b/src/services/SimulationService.java @@ -53,6 +53,7 @@ import engine.resources.common.Event; import engine.resources.common.Mesh3DTriangle; import engine.resources.common.Ray; import engine.resources.container.Traverser; +import engine.resources.database.ODBCursor; import engine.resources.objects.SWGObject; import engine.resources.scene.Planet; import engine.resources.scene.Point3D; @@ -186,13 +187,11 @@ public class SimulationService implements INetworkDispatch { } public void insertPersistentBuildings() { - EntityCursor cursor = core.getBuildingODB().getCursor(Long.class, BuildingObject.class); + ODBCursor cursor = core.getSWGObjectODB().getCursor(); - Iterator it = cursor.iterator(); - - while(it.hasNext()) { - final BuildingObject building = (BuildingObject) core.objectService.getObject(it.next().getObjectID()); - if(building == null) + while(cursor.hasNext()) { + SWGObject building = core.objectService.getObject(((SWGObject) cursor.next()).getObjectID()); + if(building == null || !(building instanceof BuildingObject)) continue; if(building.getAttachment("hasLoadedServerTemplate") == null) core.objectService.loadServerTemplate(building); diff --git a/src/services/bazaar/AuctionItem.java b/src/services/bazaar/AuctionItem.java index 92e1e41f..ffa3f6d4 100644 --- a/src/services/bazaar/AuctionItem.java +++ b/src/services/bazaar/AuctionItem.java @@ -21,6 +21,8 @@ ******************************************************************************/ package services.bazaar; +import java.io.Serializable; + import com.sleepycat.je.Environment; import com.sleepycat.je.Transaction; import com.sleepycat.persist.model.Entity; @@ -31,8 +33,10 @@ import engine.resources.objects.IPersistent; import engine.resources.objects.SWGObject; @Entity(version=1) -public class AuctionItem implements IPersistent, Comparable { +public class AuctionItem implements Comparable, Serializable { + private static final long serialVersionUID = 1L; + @PrimaryKey private long objectId; private SWGObject item; @@ -62,10 +66,7 @@ public class AuctionItem implements IPersistent, Comparable { public final static int EXPIRED = 4; public final static int OFFERED = 5; public final static int RETRIEVED = 6; - - @NotPersistent - private Transaction txn; - + public AuctionItem() { } @@ -256,16 +257,6 @@ public class AuctionItem implements IPersistent, Comparable { this.auctionOptions = auctionOptions; } - @Override - public void createTransaction(Environment env) { - txn = env.beginTransaction(null, null); - } - - @Override - public Transaction getTransaction() { - return txn; - } - public SWGObject getItem() { return item; } diff --git a/src/services/bazaar/BazaarService.java b/src/services/bazaar/BazaarService.java index 4d074039..b6e542b1 100644 --- a/src/services/bazaar/BazaarService.java +++ b/src/services/bazaar/BazaarService.java @@ -38,6 +38,7 @@ import com.sleepycat.persist.EntityCursor; import main.NGECore; import engine.clients.Client; +import engine.resources.database.ODBCursor; import engine.resources.objects.SWGObject; import engine.resources.scene.Planet; import engine.resources.scene.Point3D; @@ -81,16 +82,18 @@ public class BazaarService implements INetworkDispatch { public BazaarService(NGECore core) { this.core = core; loadAuctionItems(); - Runtime.getRuntime().addShutdownHook(new Thread(() -> { - System.out.println("Saving auction items..."); - auctionItems.forEach(item -> core.objectService.persistObject(item, Long.class, AuctionItem.class, core.getAuctionODB())); - })); + } + + public void saveAllItems() { + System.out.println("Saving auction items..."); + auctionItems.forEach(item -> core.objectService.persistObject(item.getObjectId(), item, core.getAuctionODB())); } private void loadAuctionItems() { - EntityCursor cursor = core.getAuctionODB().getCursor(Long.class, AuctionItem.class); - Iterator it = cursor.iterator(); - it.forEachRemaining(this::addAuctionItem); + ODBCursor cursor = core.getAuctionODB().getCursor(); + while(cursor.hasNext()) { + addAuctionItem((AuctionItem) cursor.next()); + } cursor.close(); } @@ -412,7 +415,7 @@ public class BazaarService implements INetworkDispatch { if(seller == null) { seller = core.objectService.getCreatureFromDB(item.getOwnerId()); seller.setBankCredits(seller.getBankCredits() + item.getPrice()); - core.objectService.persistObject(seller, Long.class, CreatureObject.class, core.getAuctionODB()); + core.objectService.persistObject(seller.getObjectID(), seller, core.getSWGObjectODB()); } } @@ -752,8 +755,8 @@ public class BazaarService implements INetworkDispatch { if(commodityLimit.get(auctionItem.getOwnerId()) != null) commodityNumber = commodityLimit.get(auctionItem.getOwnerId()); commodityLimit.put(auctionItem.getOwnerId(), commodityNumber + 1); - if(!core.getAuctionODB().contains(auctionItem.getObjectId(), Long.class, AuctionItem.class)) { - core.objectService.persistObject(auctionItem, Long.class, AuctionItem.class, core.getAuctionODB()); + if(!core.getAuctionODB().contains(auctionItem.getObjectId())) { + core.objectService.persistObject(auctionItem.getObjectId(), auctionItem, core.getAuctionODB()); } } @@ -763,7 +766,7 @@ public class BazaarService implements INetworkDispatch { if(commodityLimit.get(auctionItem.getOwnerId()) != null) commodityNumber = commodityLimit.get(auctionItem.getOwnerId()); commodityLimit.put(auctionItem.getOwnerId(), commodityNumber - 1); - core.objectService.deletePersistentObject(auctionItem, Long.class, AuctionItem.class, core.getAuctionODB(), auctionItem.getObjectId()); + core.objectService.deletePersistentObject(auctionItem.getObjectId(), core.getAuctionODB()); } } diff --git a/src/services/chat/ChatRoom.java b/src/services/chat/ChatRoom.java index 10f853c1..dd243d2d 100644 --- a/src/services/chat/ChatRoom.java +++ b/src/services/chat/ChatRoom.java @@ -21,15 +21,19 @@ ******************************************************************************/ package services.chat; +import java.io.Serializable; import java.util.Vector; + import com.sleepycat.persist.model.Entity; import com.sleepycat.persist.model.NotPersistent; import com.sleepycat.persist.model.PrimaryKey; @Entity(version=1) -public class ChatRoom { +public class ChatRoom implements Serializable { + + private static final long serialVersionUID = 1L; private String creator; // creator of the room (first name only, lowercase) private String description; // title @PrimaryKey @@ -39,7 +43,7 @@ public class ChatRoom { private Vector moderatorList = new Vector(); private Vector banList = new Vector(); @NotPersistent - private Vector userList = new Vector(); // current users + private transient Vector userList = new Vector(); // current users private boolean moderatorsOnly; private boolean privateRoom; diff --git a/src/services/chat/ChatService.java b/src/services/chat/ChatService.java index be4cbb43..26e6c611 100644 --- a/src/services/chat/ChatService.java +++ b/src/services/chat/ChatService.java @@ -42,6 +42,7 @@ import engine.clientdata.visitors.DatatableVisitor; import engine.clients.Client; import engine.resources.config.Config; import engine.resources.config.DefaultConfig; +import engine.resources.database.ODBCursor; import engine.resources.database.ObjectDatabase; import engine.resources.objects.SWGObject; import engine.resources.scene.Planet; @@ -317,7 +318,7 @@ public class ChatService implements INetworkDispatch { return; SWGObject obj = client.getParent(); - Mail mail = mailODB.get(new Integer(packet.getMailId()), Integer.class, Mail.class); + Mail mail = (Mail) mailODB.get((long) packet.getMailId()); if(obj == null || mail == null) return; @@ -352,7 +353,7 @@ public class ChatService implements INetworkDispatch { return; SWGObject obj = client.getParent(); - Mail mail = mailODB.get(new Integer(packet.getMailId()), Integer.class, Mail.class); + Mail mail = (Mail) mailODB.get((long) packet.getMailId()); if(obj == null || mail == null) return; @@ -689,15 +690,11 @@ public class ChatService implements INetworkDispatch { public void storePersistentMessage(Mail mail) { - Transaction txn = mailODB.getEnvironment().beginTransaction(null, null); - mailODB.put(mail, Integer.class, Mail.class, txn); - txn.commitSync(); + mailODB.put((long) mail.getMailId(), mail); } public void deletePersistentMessage(Mail mail) { - Transaction txn = mailODB.getEnvironment().beginTransaction(null, null); - mailODB.delete(new Integer(mail.getMailId()), Integer.class, Mail.class, txn); - txn.commitSync(); + mailODB.remove((long) mail.getMailId()); } public void loadMailHeaders(Client client) { @@ -707,14 +704,16 @@ public class ChatService implements INetworkDispatch { if(obj == null || client.getSession() == null) return; - EntityCursor cursor = mailODB.getCursor(Integer.class, Mail.class); + ODBCursor cursor = mailODB.getCursor(); - for(Mail mail : cursor) { - + while(cursor.hasNext()) { + Mail mail = (Mail) cursor.next(); if(mail.getRecieverId() == obj.getObjectID()) { sendPersistentMessageHeader(client, mail); } + } + cursor.close(); } @@ -747,7 +746,7 @@ public class ChatService implements INetworkDispatch { int id = rand.nextInt(); - if(mailODB.contains(new Integer(id), Integer.class, Mail.class)) + if(mailODB.contains((long) id)) return generateMailId(); else return id; @@ -755,7 +754,7 @@ public class ChatService implements INetworkDispatch { public Mail getMailById(int mailId) { - Mail mail = mailODB.get(new Integer(mailId), Integer.class, Mail.class); + Mail mail = (Mail) mailODB.get((long) mailId); return mail; } @@ -776,7 +775,7 @@ public class ChatService implements INetworkDispatch { Random rand = new Random(); int id = rand.nextInt(); - if (chatRoomsODB.contains(new Integer(id), Integer.class, ChatRoom.class)) + if (chatRoomsODB.contains((long) id)) return generateChatRoomId(); else return id; @@ -819,11 +818,13 @@ public class ChatService implements INetworkDispatch { createChatRoom("Politician chat for this galaxy", "Politician", "system", true); //createChatRoom("Pilot chat for this galaxy", "Pilot", "system", true); - EntityCursor cursor = chatRoomsODB.getCursor(Integer.class, ChatRoom.class); - cursor.forEach(room -> { + ODBCursor cursor = chatRoomsODB.getCursor(); + + while(cursor.hasNext()) { + ChatRoom room = (ChatRoom) cursor.next(); if (!chatRooms.containsValue(room)) chatRooms.put(room.getRoomId(), room); - }); + } cursor.close(); List planets = core.terrainService.getPlanetList(); @@ -891,9 +892,7 @@ public class ChatService implements INetworkDispatch { chatRooms.put(room.getRoomId(), room); if(store){ - Transaction txn = chatRoomsODB.getEnvironment().beginTransaction(null, null); - chatRoomsODB.put(room, Integer.class, ChatRoom.class, txn); - txn.commitSync(); + chatRoomsODB.put((long) room.getRoomId(), room); } //Console.println("Created room " + address + " with ID " + room.getRoomId()); diff --git a/src/services/chat/Mail.java b/src/services/chat/Mail.java index 5709a059..48166af5 100644 --- a/src/services/chat/Mail.java +++ b/src/services/chat/Mail.java @@ -21,13 +21,18 @@ ******************************************************************************/ package services.chat; +import java.io.Serializable; +import java.util.ArrayList; import java.util.List; + import com.sleepycat.persist.model.Entity; import com.sleepycat.persist.model.PrimaryKey; @Entity(version=1) -public class Mail { +public class Mail implements Serializable { + private static final long serialVersionUID = 1L; + @PrimaryKey private int mailId; private String senderName; @@ -36,7 +41,7 @@ public class Mail { private String message; private byte status; private int timeStamp; - private List attachments; + private List attachments = new ArrayList(); public static final byte NEW = 0x4E; public static final byte READ = 0x52; diff --git a/src/services/chat/WaypointAttachment.java b/src/services/chat/WaypointAttachment.java index 314cb08f..1a3c2d84 100644 --- a/src/services/chat/WaypointAttachment.java +++ b/src/services/chat/WaypointAttachment.java @@ -21,11 +21,15 @@ ******************************************************************************/ package services.chat; +import java.io.Serializable; + import com.sleepycat.persist.model.Persistent; @Persistent -public class WaypointAttachment { +public class WaypointAttachment implements Serializable { + private static final long serialVersionUID = 1L; + public WaypointAttachment() { } public long cellID; diff --git a/src/services/collections/ServerFirst.java b/src/services/collections/ServerFirst.java index 2b855fb4..0811d9c9 100644 --- a/src/services/collections/ServerFirst.java +++ b/src/services/collections/ServerFirst.java @@ -21,6 +21,8 @@ ******************************************************************************/ package services.collections; +import java.io.Serializable; + import org.apache.mina.core.buffer.IoBuffer; import resources.objects.Delta; @@ -28,8 +30,10 @@ import resources.objects.Delta; import com.sleepycat.persist.model.Persistent; @Persistent -public class ServerFirst extends Delta { +public class ServerFirst extends Delta implements Serializable { + private static final long serialVersionUID = 1L; + private String name; private String collection; private long time; diff --git a/src/services/guild/GuildService.java b/src/services/guild/GuildService.java index 022895de..3197e9e1 100644 --- a/src/services/guild/GuildService.java +++ b/src/services/guild/GuildService.java @@ -49,7 +49,6 @@ public class GuildService implements INetworkDispatch { object = (GuildObject) this.core.objectService.createObject("object/guild/shared_guild_object.iff", core.terrainService.getPlanetList().get(0)); } - object.createTransaction(core.getGuildODB().getEnvironment()); } public Guild createGuild(String abbreviation, String name, SWGObject leader) { diff --git a/src/services/mission/MissionObjective.java b/src/services/mission/MissionObjective.java index 8f43fe9f..df07879a 100644 --- a/src/services/mission/MissionObjective.java +++ b/src/services/mission/MissionObjective.java @@ -21,6 +21,7 @@ ******************************************************************************/ package services.mission; +import java.io.Serializable; import main.NGECore; import com.sleepycat.persist.model.Persistent; @@ -29,8 +30,10 @@ import resources.objects.creature.CreatureObject; import resources.objects.mission.MissionObject; @Persistent(version=0) -public abstract class MissionObjective { +public abstract class MissionObjective implements Serializable { + private static final long serialVersionUID = 1L; + protected long startTime; protected boolean activated; protected MissionObject parent; diff --git a/src/services/mission/MissionService.java b/src/services/mission/MissionService.java index f701ad2e..c2fc0371 100644 --- a/src/services/mission/MissionService.java +++ b/src/services/mission/MissionService.java @@ -24,6 +24,8 @@ package services.mission; import java.io.File; import java.io.IOException; import java.nio.ByteOrder; +import java.util.ArrayList; +import java.util.List; import java.util.Map; import java.util.Random; import java.util.Vector; @@ -37,7 +39,6 @@ import org.apache.mina.core.buffer.IoBuffer; import org.apache.mina.core.session.IoSession; import com.sleepycat.je.Transaction; -import com.sleepycat.persist.EntityCursor; import protocol.swg.ObjControllerMessage; import protocol.swg.objectControllerObjects.MissionAbort; @@ -59,6 +60,7 @@ import engine.clients.Client; import engine.resources.common.CRC; import engine.resources.common.NameGen; import engine.resources.container.Traverser; +import engine.resources.database.ODBCursor; import engine.resources.database.ObjectDatabase; import engine.resources.objects.SWGObject; import engine.resources.scene.Point3D; @@ -153,9 +155,9 @@ public class MissionService implements INetworkDispatch { } else if (terminalType == TerminalType.BOUNTY) { if (!object.hasSkill("class_bountyhunter_phase1_novice")) { object.sendSystemMessage("@mission/mission_generic:not_bounty_hunter_terminal", (byte) 0); - } else { + } /*else { handleMissionListRequest(core.objectService.getObject(request.getObjectId()), request.getTickCount(), TerminalType.BOUNTY); - } + }*/ } else if (terminalType == TerminalType.ENTERTAINER) { } else if (terminalType == TerminalType.ARTISAN) { @@ -205,9 +207,13 @@ public class MissionService implements INetworkDispatch { } public void handleMissionAbort(CreatureObject creature, MissionObject mission) { + handleMissionAbort(creature, mission, false); + } + + public void handleMissionAbort(CreatureObject creature, MissionObject mission, boolean silent) { MissionObjective objective = mission.getObjective(); - if (objective != null) + if (objective != null && !silent) objective.abort(core, creature); core.objectService.destroyObject(mission.getObjectId()); @@ -217,7 +223,7 @@ public class MissionService implements INetworkDispatch { File missionFolder = new File("./clientdata/string/en/mission"); File[] missionFiles = missionFolder.listFiles(); - int missionStrings = 0; + //int missionStrings = 0; for (int i = 0; i < missionFiles.length; i++) { if (missionFiles[i].getName().contains("_easy") || missionFiles[i].getName().contains("_medium") || missionFiles[i].getName().contains("_hard")) { @@ -239,7 +245,7 @@ public class MissionService implements INetworkDispatch { continue; } } catch (Exception e) { e.printStackTrace(); } - missionStrings++; + //missionStrings++; } } //System.out.println("Loaded " + missionStrings + " mission entry counts."); @@ -279,14 +285,13 @@ public class MissionService implements INetworkDispatch { MissionObject mission = (MissionObject) obj; - if (typeOneCount.get() < 4) { + if (typeOneCount.get() < 5) { if (type == TerminalType.GENERIC) randomDeliveryMission(player, mission); else if (type == TerminalType.BOUNTY) - //randomBountyMission(player, mission); - return; + randomBountyMission(player, mission); else if (type == TerminalType.ARTISAN) return; @@ -297,7 +302,7 @@ public class MissionService implements INetworkDispatch { mission.setRepeatCount(requestCounter); typeOneCount.incrementAndGet(); - } else if (typeTwoCount.get() < 4) { + } else if (typeTwoCount.get() < 5) { if (type == TerminalType.GENERIC) return; @@ -440,7 +445,7 @@ public class MissionService implements INetworkDispatch { } } - if (bountyTarget == null) + if (bountyTarget == null || bountyTarget.getAssignedHunters().contains(player.getObjectId())) return; mission.setMissionType("bounty"); @@ -448,17 +453,20 @@ public class MissionService implements INetworkDispatch { String missionStf = "mission/mission_bounty_jedi"; if (!bountyTarget.getProfession().equals("")) { // TODO: Smuggler mission checks. - if (bountyTarget.getFaction().equals("neutral")) { + if (bountyTarget.getFaction().equals("neutral")) { // There were no neutral bounty missions. Remove this when done testing. mission.setMissionTargetName("@mission/mission_bounty_jedi:neutral_jedi"); mission.setMissionId(3); + mission.setCreator("Corporate Sector Authority"); } else if (bountyTarget.getFaction().equals("rebel")) { - mission.setMissionTargetName("@mission/mission_bounty_jedi:rebel_jedi"); + mission.setMissionTargetName("Rebel Bounty"); mission.setMissionId(2); + mission.setCreator("The Galactic Empire"); } else if (bountyTarget.getFaction().equals("imperial")) { - mission.setMissionTargetName("@mission/mission_bounty_jedi:imperial_jedi"); + mission.setMissionTargetName("Imperial Bounty"); mission.setMissionId(1); + mission.setCreator("The Alliance"); } mission.setMissionTitle(missionStf); mission.setMissionDescription(missionStf); @@ -477,7 +485,7 @@ public class MissionService implements INetworkDispatch { mission.setMissionDescription(missionStf, "s"); } - mission.setMissionLevel(90); + mission.setMissionLevel(new Random().nextInt(100 - 95) + 95); mission.setCreditReward(bountyTarget.getCreditReward()); @@ -513,7 +521,7 @@ public class MissionService implements INetworkDispatch { return null; } - public BountyListItem createNewBounty(CreatureObject bountyTarget, int reward) { + public BountyListItem createNewBounty(CreatureObject bountyTarget, long placer, int reward) { PlayerObject player = (PlayerObject) bountyTarget.getSlottedObject("ghost"); if (player == null) return null; @@ -523,9 +531,10 @@ public class MissionService implements INetworkDispatch { BountyListItem bounty = new BountyListItem(bountyTarget.getObjectId(), reward, core.playerService.getFormalProfessionName(player.getProfession()), bountyTarget.getFaction(), bountyTarget.getCustomName()); - Transaction txn = bountiesODB.getEnvironment().beginTransaction(null, null); - bountiesODB.put(bounty, Long.class, BountyListItem.class, txn); - txn.commitSync(); + if (placer != 0) + bounty.getBountyPlacers().add(placer); + + bountiesODB.put(bounty.getObjectId(), bounty); bountyList.add(bounty); @@ -533,53 +542,51 @@ public class MissionService implements INetworkDispatch { return bounty; } - public boolean addToExistingBounty(CreatureObject bountyTarget, int amountToAdd) { + public boolean addToExistingBounty(long bountyTarget, long placer, int amountToAdd) { - BountyListItem bounty = getBountyListItem(bountyTarget.getObjectId()); + BountyListItem bounty = getBountyListItem(bountyTarget); if (bounty == null) return false; bounty.addBounty(amountToAdd); + + if (placer != 0 && !bounty.getBountyPlacers().contains(placer)) + bounty.getBountyPlacers().add(placer); - Transaction txn = bountiesODB.getEnvironment().beginTransaction(null, null); - bountiesODB.put(bounty, Long.class, BountyListItem.class, txn); - txn.commitSync(); + bountiesODB.put(bounty.getObjectId(), bounty); //System.out.println("Added bounty of " + amountToAdd + " to " + bounty.getName()); return true; } - public boolean removeBounty(CreatureObject bountyTarget, boolean listRemove) { + public boolean removeBounty(long bountyTarget, boolean listRemove) { Transaction txn = bountiesODB.getEnvironment().beginTransaction(null, null); if (listRemove) - bountyList.remove(bountiesODB.get(bountyTarget.getObjectId(), Long.class, BountyListItem.class)); + bountyList.remove(bountiesODB.get(bountyTarget)); - bountiesODB.delete(bountyTarget.getObjectId(), Long.class, BountyListItem.class, txn); + bountiesODB.remove(bountyTarget); txn.commitSync(); return true; } - public boolean removeBounty(CreatureObject bountyTarget) { + public boolean removeBounty(long bountyTarget) { return removeBounty(bountyTarget, true); } private void cleanupBounties() { - AtomicInteger bountyCount = new AtomicInteger(); - Transaction txn = bountiesODB.getEnvironment().beginTransaction(null, null); - EntityCursor bountyCursor = bountiesODB.getEntityStore().getPrimaryIndex(Long.class, BountyListItem.class).entities(txn, null); - bountyCursor.forEach(bounty -> { + List bounties = new ArrayList(); + ODBCursor cursor = bountiesODB.getCursor(); + while(cursor.hasNext()) { + BountyListItem bounty = (BountyListItem) cursor.next(); if (!core.characterService.playerExists(bounty.getObjectId())) { - bountyCursor.delete(); - bountyCount.getAndIncrement(); + bounties.add(bounty); } - }); - bountyCursor.close(); - txn.commitSync(); - - if (bountyCount.get() != 0) - System.out.println("Removed " + bountyCount.get() + " bounties."); + } + bounties.stream().mapToLong(b -> b.getObjectId()).forEach(bountiesODB::remove); + if (bounties.size() != 0) + System.out.println("Removed " + bounties.size() + " bounties."); } @Override diff --git a/src/services/object/DuplicateId.java b/src/services/object/DuplicateId.java index db618527..55b03ab6 100644 --- a/src/services/object/DuplicateId.java +++ b/src/services/object/DuplicateId.java @@ -21,12 +21,16 @@ ******************************************************************************/ package services.object; +import java.io.Serializable; + import com.sleepycat.persist.model.Entity; import com.sleepycat.persist.model.PrimaryKey; @Entity -public class DuplicateId { +public class DuplicateId implements Serializable { + private static final long serialVersionUID = 1L; + @PrimaryKey private String key; private long objectId; diff --git a/src/services/object/ObjectId.java b/src/services/object/ObjectId.java index 36df1736..1f8362fb 100644 --- a/src/services/object/ObjectId.java +++ b/src/services/object/ObjectId.java @@ -21,12 +21,16 @@ ******************************************************************************/ package services.object; +import java.io.Serializable; + import com.sleepycat.persist.model.Entity; import com.sleepycat.persist.model.PrimaryKey; @Entity -public class ObjectId { +public class ObjectId implements Serializable { + private static final long serialVersionUID = 1L; + @PrimaryKey public long objectId; diff --git a/src/services/object/ObjectService.java b/src/services/object/ObjectService.java index 0923192d..a08928db 100644 --- a/src/services/object/ObjectService.java +++ b/src/services/object/ObjectService.java @@ -88,6 +88,7 @@ import engine.resources.container.Traverser; import engine.resources.container.WorldCellPermissions; import engine.resources.container.WorldPermissions; import engine.resources.database.DatabaseConnection; +import engine.resources.database.ODBCursor; import engine.resources.database.ObjectDatabase; import engine.resources.objects.IPersistent; import engine.resources.objects.SWGObject; @@ -97,6 +98,7 @@ import engine.resources.scene.Quaternion; import engine.resources.service.INetworkDispatch; import engine.resources.service.INetworkRemoteEvent; import main.NGECore; +import resources.objectives.BountyMissionObjective; import resources.objects.Delta; import resources.objects.building.BuildingObject; import resources.objects.cell.CellObject; @@ -145,7 +147,6 @@ public class ObjectService implements INetworkDispatch { Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { - core.getObjectIdODB().getEnvironment().flushLog(true); synchronized(objectList) { for(SWGObject obj : objectList.values()) { @@ -155,6 +156,8 @@ public class ObjectService implements INetworkDispatch { } } + core.bazaarService.saveAllItems(); + core.closeODBs(); } }); @@ -173,25 +176,20 @@ public class ObjectService implements INetworkDispatch { } public void loadBuildings() { - EntityCursor cursor = core.getBuildingODB().getCursor(Long.class, BuildingObject.class); - - Iterator it = cursor.iterator(); - - while(it.hasNext()) { - final BuildingObject building = it.next(); + ODBCursor cursor = core.getSWGObjectODB().getCursor(); + + while(cursor.hasNext()) { + final SWGObject building = (SWGObject) cursor.next(); + if(!(building instanceof BuildingObject)) + continue; objectList.put(building.getObjectID(), building); Planet planet = core.terrainService.getPlanetByID(building.getPlanetId()); building.setPlanet(planet); - building.viewChildren(building, true, true, new Traverser() { - - @Override - public void process(SWGObject object) { - objectList.put(object.getObjectID(), object); - if(object.getParentId() != 0 && object.getContainer() == null) - object.setParent(building); - object.getContainerInfo(object.getTemplate()); - } - + building.viewChildren(building, true, true, (object) -> { + objectList.put(object.getObjectID(), object); + if(object.getParentId() != 0 && object.getContainer() == null) + object.setParent(building); + object.getContainerInfo(object.getTemplate()); }); } @@ -338,10 +336,8 @@ public class ObjectService implements INetworkDispatch { object.setAttachment("customServerTemplate", customServerTemplate); object.setisInSnapshot(isSnapshot); - - if(!core.getObjectIdODB().contains(objectID, Long.class, ObjectId.class)) { - core.getObjectIdODB().put(new ObjectId(objectID), Long.class, ObjectId.class); - } + if(!core.getObjectIdODB().contains(objectID)) + core.getObjectIdODB().put(objectID, new ObjectId(objectID)); // Set Options - easier to set them across the board here // because we'll be spawning them despite most of them being unscripted. @@ -540,13 +536,11 @@ public class ObjectService implements INetworkDispatch { } - EntityCursor cursor = core.getCreatureODB().getCursor(Long.class, CreatureObject.class); + ODBCursor cursor = core.getSWGObjectODB().getCursor(); - Iterator it = cursor.iterator(); - - while(it.hasNext()) { - if(it.next().getCustomName().equals(customName)) - return it.next(); + while(cursor.hasNext()) { + if(((SWGObject) cursor.next()).getCustomName().equals(customName)) + return (SWGObject) cursor.next(); } return null; @@ -566,13 +560,11 @@ public class ObjectService implements INetworkDispatch { } - EntityCursor cursor = core.getCreatureODB().getCursor(Long.class, CreatureObject.class); + ODBCursor cursor = core.getSWGObjectODB().getCursor(); - Iterator it = cursor.iterator(); - - while(it.hasNext()) { - if(it.next().getCustomName().startsWith(customName)) - return it.next(); + while(cursor.hasNext()) { + if(((SWGObject) cursor.next()).getCustomName().startsWith(customName)) + return (SWGObject) cursor.next(); } return null; @@ -580,21 +572,15 @@ public class ObjectService implements INetworkDispatch { } public CreatureObject getCreatureFromDB(long objectId) { - CreatureObject object = core.getCreatureODB().get(new Long(objectId), Long.class, CreatureObject.class); - + SWGObject object = (SWGObject) core.getSWGObjectODB().get(objectId); + if(!(object instanceof CreatureObject)) + return null; if (object != null && getObject(object.getObjectID()) == null) { loadServerTemplate(object); - - object.viewChildren(object, true, true, new Traverser() { - - public void process(SWGObject child) { - loadServerTemplate(child); - } - - }); + object.viewChildren(object, true, true, (child) -> loadServerTemplate(child)); } - return object; + return (CreatureObject) object; } public long generateObjectID() { @@ -627,7 +613,7 @@ public class ObjectService implements INetworkDispatch { } catch (SQLException e) { e.printStackTrace(); } - if(getObject(newId) != null || core.getObjectIdODB().contains(newId, Long.class, ObjectId.class)) + if(getObject(newId) != null || core.getObjectIdODB().contains(newId)) found = false; else found = true; @@ -645,13 +631,11 @@ public class ObjectService implements INetworkDispatch { long objectId = 0; - if (core.getDuplicateIdODB().contains(key, String.class, DuplicateId.class)) { - objectId = core.getDuplicateIdODB().get(key, String.class, DuplicateId.class).getObjectId(); + if (core.getDuplicateIdODB().contains(key)) { + objectId = ((DuplicateId) core.getDuplicateIdODB().get(key)).getObjectId(); } else { objectId = generateObjectID(); - Transaction txn = core.getDuplicateIdODB().getEnvironment().beginTransaction(null, null); - core.getDuplicateIdODB().put(new DuplicateId(key, objectId), String.class, DuplicateId.class, txn); - txn.commitSync(); + core.getDuplicateIdODB().put(key, new DuplicateId(key, objectId)); } return objectId; @@ -913,10 +897,25 @@ public class ObjectService implements INetworkDispatch { if(!core.getConfig().getString("MOTD").equals("")) creature.sendSystemMessage(core.getConfig().getString("MOTD"), (byte) 2); - BountyListItem bounty = core.getBountiesODB().get(creature.getObjectId(), Long.class, BountyListItem.class); + BountyListItem bounty = (BountyListItem) core.getBountiesODB().get(creature.getObjectId()); if (bounty != null) core.missionService.getBountyList().add(bounty); + if (creature.getSlottedObject("datapad") != null) { + creature.getSlottedObject("datapad").viewChildren(creature, true, false, new Traverser() { + + @Override + public void process(SWGObject obj) { + if (obj instanceof MissionObject) { + MissionObject mission = (MissionObject) obj; + if (mission.getMissionType().equals("bounty")) { + ((BountyMissionObjective) mission.getObjective()).checkBountyActiveStatus(core); + } + } + } + }); + } + core.playerService.postZoneIn(creature); } @@ -1112,13 +1111,11 @@ public class ObjectService implements INetworkDispatch { String key = "" + CRC.StringtoCRC(planet.getName()) + CRC.StringtoCRC(template) + type + containerId + cellIndex + x + py + z; long newObjectId = 0; - if (core.getDuplicateIdODB().contains(key, String.class, DuplicateId.class)) { - newObjectId = core.getDuplicateIdODB().get(key, String.class, DuplicateId.class).getObjectId(); + if (core.getDuplicateIdODB().contains(key)) { + newObjectId = ((DuplicateId) core.getDuplicateIdODB().get(key)).getObjectId(); } else { newObjectId = generateObjectID(); - Transaction txn = core.getDuplicateIdODB().getEnvironment().beginTransaction(null, null); - core.getDuplicateIdODB().put(new DuplicateId(key, newObjectId), String.class, DuplicateId.class, txn); - txn.commitSync(); + core.getDuplicateIdODB().put(key, new DuplicateId(key, newObjectId)); } duplicate.put(objectId, newObjectId); @@ -1129,7 +1126,7 @@ public class ObjectService implements INetworkDispatch { SWGObject object; if(objectId != 0 && containerId == 0) { if(portalCRC != 0) { - if (core.getBuildingODB().contains(objectId, Long.class, BuildingObject.class) && !duplicate.containsValue(objectId)) + if (core.getSWGObjectODB().contains(objectId) && !duplicate.containsValue(objectId)) continue; containers.add(objectId); object = createObject(template, objectId, planet, new Point3D(px + x1, py, pz + z1), new Quaternion(qw, qx, qy, qz), null, true, false); @@ -1181,9 +1178,7 @@ public class ObjectService implements INetworkDispatch { } for(BuildingObject building : persistentBuildings) { - building.createTransaction(core.getBuildingODB().getEnvironment()); - core.getBuildingODB().put(building, Long.class, BuildingObject.class, building.getTransaction()); - building.getTransaction().commitSync(); + core.getSWGObjectODB().put(building.getObjectID(), building); destroyObject(building); } @@ -1210,16 +1205,12 @@ public class ObjectService implements INetworkDispatch { return count.get(); } - public void persistObject(IPersistent object, Class keyClass, Class valueClass, ObjectDatabase odb) { - object.createTransaction(odb.getEnvironment()); - core.getAuctionODB().put(object, keyClass, valueClass, object.getTransaction()); - object.getTransaction().commitSync(); + public void persistObject(long key, Object value, ObjectDatabase odb) { + odb.put(key, value); } - public void deletePersistentObject(IPersistent object, Class keyClass, Class valueClass, ObjectDatabase odb, Object key) { - object.createTransaction(odb.getEnvironment()); - core.getAuctionODB().delete(key, keyClass, valueClass, object.getTransaction()); - object.getTransaction().commitSync(); + public void deletePersistentObject(long key, ObjectDatabase odb) { + odb.remove(key); } } diff --git a/src/services/object/ObjectTransactionManager.java b/src/services/object/ObjectTransactionManager.java deleted file mode 100644 index f4fcfc6a..00000000 --- a/src/services/object/ObjectTransactionManager.java +++ /dev/null @@ -1,98 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2013 - * - * This File is part of NGECore2. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Using NGEngine to work with NGECore2 is making a combined work based on NGEngine. - * Therefore all terms and conditions of the GNU Lesser General Public License cover the combination. - ******************************************************************************/ -package services.object; - -import java.util.Collection; -import java.util.Iterator; - -import com.sleepycat.je.Transaction; - -import engine.resources.objects.IPersistent; -import engine.resources.objects.SWGObject; - - -/** - * This Class is used to periodically save all Objects using transactions to disk. - * Remember that you still need commit transactions manually whenever an object using transactions is removed from zone i.e. when a player logs out. - * @author Light - */ -public class ObjectTransactionManager implements Runnable { - - private ObjectService objService; - private int cycleTime; - - /** - * - * @param objService ObjectService - * @param cycleTime Time between each full object save in ms. - */ - public ObjectTransactionManager(ObjectService objService, int cycleTime) { - - this.objService = objService; - this.cycleTime = cycleTime; - - } - - - @Override - public void run() { - - try { - - Thread.sleep(cycleTime); - - Collection swgObjects = objService.getObjectList().values(); - - synchronized(swgObjects) { - - Iterator it = swgObjects.iterator(); - - while(it.hasNext()) { - - SWGObject obj = it.next(); - - if(obj instanceof IPersistent && !obj.isInSnapshot() && obj.isPersistent()) { - - if(((IPersistent) obj).getTransaction() == null) - continue; - - if(!((IPersistent) obj).getTransaction().isValid()) - continue; - - Transaction txn = ((IPersistent) obj).getTransaction(); - txn.commitSync(); - - } - - } - - } - - } catch (InterruptedException e) { - e.printStackTrace(); - } - - } - -} - - diff --git a/src/services/playercities/PlayerCity.java b/src/services/playercities/PlayerCity.java index 34afeef9..066c015e 100644 --- a/src/services/playercities/PlayerCity.java +++ b/src/services/playercities/PlayerCity.java @@ -21,6 +21,7 @@ ******************************************************************************/ package services.playercities; +import java.io.Serializable; import java.util.ArrayList; import java.util.Arrays; import java.util.Date; @@ -40,9 +41,12 @@ import engine.resources.scene.Point3D; * @author Charon */ -public class PlayerCity { +public class PlayerCity implements Serializable { + + private static final long serialVersionUID = 1L; public static final int DESERTED = 0; + public static final int NEWCITY = 0; public static final int OUTPOST = 1; public static final int VILLAGE = 2; public static final int TOWNSHIP = 3; @@ -106,8 +110,11 @@ public class PlayerCity { private boolean registered = false; private boolean zoningEnabled = false; - private final long cityUpdateSpan = 7*86400*1000; - private final long legislationPeriod = 21*86400*1000; + //private final long cityUpdateSpan = 7*86400*1000; + private final long cityUpdateSpan = 100*1000; + + //private final long legislationPeriod = 21*86400*1000; + private final long legislationPeriod = 100*1000; private Vector placedStructures = new Vector(); private Vector citizens = new Vector(); @@ -129,6 +136,7 @@ public class PlayerCity { setNextElectionDate(foundationTime+legislationPeriod); citizens.add(founder.getObjectID()); this.cityID = cityID; + setMayorID(founder.getObjectID()); } public void handleGrantZoning() { @@ -156,36 +164,67 @@ public class PlayerCity { public void processCityUpdate() { // has something changed? System.out.println("processCityUpdate"); - int censusResult = citizens.size(); - // ToDo: Consider 1 rank per update changes - if (censusResult<5){ - setRank(DESERTED); // City is technically not a city anymore - setCityRadius(0); - } + int censusResult = citizens.size(); + int currentRank = getRank(); - if (censusResult>=5 && censusResult<10){ - setRank(OUTPOST); - setCityRadius(150); - } + switch (currentRank) { + case NEWCITY : if (censusResult>=5){ + setRank(++currentRank); // Expand to Outpost + sendCityExpandMailAll(); + } + + if (censusResult<5){ + // kill city + } + break; + + case OUTPOST : if (censusResult>=10){ + setRank(++currentRank); // Expand to Village + sendCityExpandMailAll(); + } + if (censusResult<5){ + setRank(--currentRank); // Contract to Deserted + sendCityContractMailAll(); + } + break; + + case VILLAGE : if (censusResult>=15){ + setRank(++currentRank); // Expand to Township + sendCityExpandMailAll(); + } + if (censusResult<10){ + setRank(--currentRank); // Contract to Outpost + sendCityContractMailAll(); + } + break; + + case TOWNSHIP : if (censusResult>=30){ + setRank(++currentRank); // Expand to City + sendCityExpandMailAll(); + } + if (censusResult<15){ + setRank(--currentRank); // Contract to Village + sendCityContractMailAll(); + } + break; + + case CITY : if (censusResult>=40){ + setRank(++currentRank); // Expand to Metropolis + sendCityExpandMailAll(); + } + if (censusResult<15){ + setRank(--currentRank); // Contract to Township + sendCityContractMailAll(); + } + break; + + case METROPOLIS : if (censusResult<40){ + setRank(--currentRank); // Contract to City + sendCityContractMailAll(); + } + break; + - if (censusResult>=10 && censusResult<15){ - setRank(VILLAGE); - setCityRadius(200); - } - - if (censusResult>=15 && censusResult<30){ - setRank(TOWNSHIP); - setCityRadius(300); - } - - if (censusResult>=30 && censusResult<40){ - setRank(CITY); - setCityRadius(400); - } - - if (censusResult>=40){ - setRank(METROPOLIS); - setCityRadius(450); } // collect taxes @@ -212,6 +251,10 @@ public class PlayerCity { setNextCityUpdate(System.currentTimeMillis()+cityUpdateSpan); } + public void cityFixUp(){ + + } + public void demolishHighRankStructures() { // Check if there are any structures in the city // that require a higher rank than the current one @@ -263,8 +306,10 @@ public class PlayerCity { if (citizenList.contains(founderId) && (long)citizenObject.getAttachment("residentCity")==this.getCityID()) founderCitizenCount++; } - if (founderCitizenCount==founders.size()) - return true; // All founders are citizens now + if (founderCitizenCount==founders.size()){ + return true; // All founders are citizens now + + } return false; } @@ -475,6 +520,7 @@ public class PlayerCity { public void setCityName(String cityName) { this.cityName = cityName; sendNameChangeMail(cityName); + return; } public int getCityID() { @@ -548,6 +594,20 @@ public class PlayerCity { public void setZoningEnabled(boolean zoningEnabled) { this.zoningEnabled = zoningEnabled; } + + public boolean isMilitiaMember(long actor){ + if (getMilitiaList().contains(actor)) + return true; + + return false; + } + + public boolean hasCitizen(long actor){ + if (getCitizens().contains(actor)) + return true; + + return false; + } public static String[] getSpecialisationSTFNames() { return specialisationSTFNames; @@ -695,5 +755,95 @@ public class PlayerCity { } } + + public void sendCityExpandMailAll() { + Vector citizenList = getCitizens(); + for (long citizen : citizenList){ + CreatureObject citizenObject = (CreatureObject) NGECore.getInstance().objectService.getObject(citizen); + Mail actorMail = new Mail(); + actorMail.setMailId(NGECore.getInstance().chatService.generateMailId()); + actorMail.setRecieverId(citizen); + actorMail.setStatus(Mail.NEW); + actorMail.setTimeStamp((int) (new Date().getTime() / 1000)); + actorMail.setMessage("@city/city:city_expand_body"); + actorMail.setSubject("@city/city:city_expand_subject"); + actorMail.setSenderName("City " + this.cityName); + + List attachments = new ArrayList(); + WaypointObject constructionWaypoint = (WaypointObject)NGECore.getInstance().objectService.createObject("object/waypoint/shared_world_waypoint_blue.iff", citizenObject.getPlanet(), citizenObject.getPosition().x, 0 ,citizenObject.getPosition().z); + WaypointAttachment attachment = new WaypointAttachment(); + attachment.active = false; + attachment.cellID = constructionWaypoint.getCellId(); + attachment.color = (byte)1; + attachment.name = "City"; + attachment.planetCRC = engine.resources.common.CRC.StringtoCRC(citizenObject.getPlanet().getName()); + attachment.positionX = citizenObject.getPosition().x; + attachment.positionY = 0; + attachment.positionZ = citizenObject.getPosition().z; + attachments.add(attachment); + actorMail.setAttachments(attachments); + + NGECore.getInstance().chatService.storePersistentMessage(actorMail); + + } + } + + public void sendCityContractMailAll() { + + Vector citizenList = getCitizens(); + for (long citizen : citizenList){ + CreatureObject citizenObject = (CreatureObject) NGECore.getInstance().objectService.getObject(citizen); + Mail actorMail = new Mail(); + actorMail.setMailId(NGECore.getInstance().chatService.generateMailId()); + actorMail.setRecieverId(citizen); + actorMail.setStatus(Mail.NEW); + actorMail.setTimeStamp((int) (new Date().getTime() / 1000)); + actorMail.setMessage("@city/city:city_contract_body"); + actorMail.setSubject("@city/city:city_contract_subject"); + actorMail.setSenderName("City " + this.cityName); + + List attachments = new ArrayList(); + WaypointObject constructionWaypoint = (WaypointObject)NGECore.getInstance().objectService.createObject("object/waypoint/shared_world_waypoint_blue.iff", citizenObject.getPlanet(), citizenObject.getPosition().x, 0 ,citizenObject.getPosition().z); + WaypointAttachment attachment = new WaypointAttachment(); + attachment.active = false; + attachment.cellID = constructionWaypoint.getCellId(); + attachment.color = (byte)1; + attachment.name = "City"; + attachment.planetCRC = engine.resources.common.CRC.StringtoCRC(citizenObject.getPlanet().getName()); + attachment.positionX = citizenObject.getPosition().x; + attachment.positionY = 0; + attachment.positionZ = citizenObject.getPosition().z; + attachments.add(attachment); + actorMail.setAttachments(attachments); + + NGECore.getInstance().chatService.storePersistentMessage(actorMail); + } + } + + + + + // Test method to be deleted later + public void Add10MoreCitizens() { + synchronized(citizens){ + for (int i=0;i<10;i++){ + this.citizens.add(this.getMayorID()); + } + + } + } + + + // Test method to be deleted later + public void Deduct10Citizens() { + int citizenCount = this.getCitizens().size(); + synchronized(citizens){ + this.citizens.clear(); + + for (int i=0;i playerCities = new Vector(); private int cityID = 0; // This must be persisted or handled via objectservice somehow + // static helper variable to be deleted later + public static boolean sandboxCityBuilt = false; + public PlayerCityService(NGECore core) { this.core = core; @@ -95,7 +102,8 @@ public class PlayerCityService implements INetworkDispatch { synchronized(playerCities){ for (PlayerCity city : playerCities){ int radius = city.getCityRadius(); - if (object.getPosition().getDistance2D(city.getCityCenterPosition()) 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 +163,99 @@ public class PlayerCityService implements INetworkDispatch { }); core.suiService.openSUIWindow(window); } + + + // Test method to be deleted later + public void buildSandboxTestCity(CreatureObject founder) { + + if (sandboxCityBuilt) + return; + + float positionX = 2170.0F; + float positionY = 1.0F; + float positionZ = -4659.0F; + + String structureTemplate = "object/building/player/city/shared_cityhall_tatooine.iff"; + + BuildingObject cityHall = (BuildingObject) core.objectService.createObject(structureTemplate, 0, founder.getPlanet(), new Point3D(positionX, positionY, positionZ), founder.getOrientation()); + core.simulationService.add(cityHall, cityHall.getPosition().x, cityHall.getPosition().z, true); + + SWGObject sign = core.objectService.createChildObject((SWGObject)cityHall, "object/tangible/sign/player/shared_house_address.iff", -7.39F, 2.36F, 2, -1, 0, -1); + cityHall.setAttachment("structureSign", sign); + + PlayerCity sandboxCity = null; + synchronized(playerCities){ + sandboxCity = new PlayerCity(founder,cityID++); + sandboxCity.setCityName("Sandbox City"); + playerCities.add(sandboxCity); + } + + cityHall.setAttachment("structureCity", sandboxCity.getCityID()); + founder.setAttachment("residentCity", sandboxCity.getCityID()); + // Name the sign +// TangibleObject sign = (TangibleObject) cityHall.getAttachment("structureSign"); +// String playerFirstName = founder.getCustomName().split(" ")[0]; +// +// if (sign !=null) +// sign.setCustomName2(playerFirstName + "'s House"); + + + + // Structure management + Vector admins = new Vector<>(); + admins.add(founder.getObjectID()); + + cityHall.setAttachment("structureOwner", founder.getObjectID()); + cityHall.setAttachment("structureAdmins", admins); + cityHall.setDeedTemplate("object/tangible/deed/city_deed/shared_cityhall_tatooine_deed.iff"); + cityHall.setBMR(325); + cityHall.setConditionDamage(100); + + + positionY = core.terrainService.getHeight(founder.getPlanetId(), positionX, positionZ); + founder.setPosition(new Point3D(positionX,positionY,positionZ+50)); + core.simulationService.teleport(founder, new Point3D(positionX,positionY,positionZ+50), founder.getOrientation(), 0); + + TangibleObject swoopDeed = (TangibleObject) core.objectService.createObject("object/tangible/deed/vehicle_deed/shared_speederbike_swoop_deed.iff", founder.getPlanet()); + SWGObject inventory = founder.getSlottedObject("inventory"); + inventory.add(swoopDeed); + + TangibleObject shuttleportDeed = (TangibleObject) core.objectService.createObject("object/tangible/deed/city_deed/shared_shuttleport_tatooine_deed.iff", founder.getPlanet()); + inventory.add(shuttleportDeed); + + TangibleObject garden1 = (TangibleObject) core.objectService.createObject("object/tangible/deed/city_deed/shared_garden_tatooine_sml_01_deed.iff", founder.getPlanet()); + inventory.add(garden1); + + + //structureTemplate = "object/building/player/city/shared_shuttleport_tatooine.iff"; + structureTemplate = "object/building/tatooine/shared_shuttleport_tatooine.iff"; + positionX = 2170.0F; + positionY = 1.0F; + positionZ = -4559.0F; + positionY = core.terrainService.getHeight(founder.getPlanetId(), positionX, positionZ); + + //StructureObject shuttlePort = (StructureObject) core.objectService.createObject(structureTemplate, 0, founder.getPlanet(), new Point3D(positionX, positionY, positionZ), founder.getOrientation()); + //BuildingObject shuttlePort = (BuildingObject) core.objectService.createObject(structureTemplate, 0, founder.getPlanet(), new Point3D(positionX, positionY, positionZ), founder.getOrientation()); + //shuttlePort.setAttachment("cellsSorted", new Boolean(true)); + //"bigSpawnRange" + + //core.simulationService.add(shuttlePort, shuttlePort.getPosition().x, shuttlePort.getPosition().z, true); +// sign = core.objectService.createChildObject((SWGObject)shuttlePort, "object/tangible/sign/player/shared_house_address.iff", -7.39F, 2.36F, 2, -1, 0, -1); +// shuttlePort.setAttachment("structureSign", sign); + + // Structure management + admins = new Vector<>(); + admins.add(founder.getObjectID()); + +// shuttlePort.setAttachment("structureOwner", founder.getObjectID()); +// shuttlePort.setAttachment("structureAdmins", admins); +// shuttlePort.setDeedTemplate("object/tangible/deed/city_deed/shared_cityhall_tatooine_deed.iff"); +// shuttlePort.setBMR(12); +// shuttlePort.setConditionDamage(100); + + sandboxCityBuilt = true; + } + @Override public void insertOpcodes(Map arg0, diff --git a/src/services/resources/ResourceService.java b/src/services/resources/ResourceService.java index 0cb2cab1..d6719c0b 100644 --- a/src/services/resources/ResourceService.java +++ b/src/services/resources/ResourceService.java @@ -33,6 +33,7 @@ import com.sleepycat.persist.EntityCursor; import main.NGECore; import engine.resources.common.CRC; +import engine.resources.database.ODBCursor; import engine.resources.objects.SWGObject; import engine.resources.scene.Planet; import engine.resources.scene.Point3D; @@ -114,9 +115,8 @@ public class ResourceService implements INetworkDispatch { // createCollections2(); // createCollections3(); // } else { - EntityCursor cursor = core.getResourceRootsODB().getCursor(Integer.class, ResourceRoot.class); - Iterator it = cursor.iterator(); - if(!it.hasNext()) { + ODBCursor cursor = core.getResourceRootsODB().getCursor(); + if(!cursor.hasNext()) { createCollections(); createCollections2(); createCollections3(); @@ -133,12 +133,11 @@ public class ResourceService implements INetworkDispatch { // loads the resource roots at server start public void loadResourceRoots() { - EntityCursor cursor = core.getResourceRootsODB().getCursor(Integer.class, ResourceRoot.class); - Iterator it = cursor.iterator(); + ODBCursor cursor = core.getResourceRootsODB().getCursor(); int loadedResourceRootsCounter = 0; System.out.println("Loading resource roots..."); - while(it.hasNext()) { - final ResourceRoot resourceRoot = it.next(); + while(cursor.hasNext()) { + final ResourceRoot resourceRoot = (ResourceRoot) cursor.next(); System.err.println("resourceRoot loaded ID: " + resourceRoot.getResourceRootID() + " " + resourceRoot.getResourceFileName()); core.resourceService.add_resourceRoot(resourceRoot); loadedResourceRootsCounter++; @@ -154,12 +153,11 @@ public class ResourceService implements INetworkDispatch { // loads the currently spawned resources at server start public void loadResources() { - EntityCursor cursor = core.getResourcesODB().getCursor(Long.class, GalacticResource.class); - Iterator it = cursor.iterator(); + ODBCursor cursor = core.getResourcesODB().getCursor(); int loadedResourceCounter = 0; System.out.println("Loading resources..."); - while(it.hasNext()) { - final GalacticResource resource = it.next(); + while(cursor.hasNext()) { + final GalacticResource resource = (GalacticResource) cursor.next(); System.err.println("resource " + resource.getName() + " rootID " + resource.getResourceRootID()); core.objectService.getObjectList().put(resource.getId(), resource); @@ -10800,9 +10798,7 @@ public class ResourceService implements INetworkDispatch { for (int i=0;i mobiles = new Vector(); + + public DynamicSpawnArea(Planet planet, AbstractCollidable area, DynamicSpawnGroup spawnGroup) { super(planet, area); + this.spawnGroup = spawnGroup; } @Override @Handler public void onEnter(EnterEvent event) { + SWGObject object = event.object; + + if(object == null || !(object instanceof CreatureObject)) + return; + + CreatureObject creature = (CreatureObject) object; + + if(creature.getSlottedObject("ghost") == null) + return; + + creature.getEventBus().subscribe(this); + // spawn some creatures + for(int i = 0; i < 5; i++) + spawnCreature(creature); + } @Override @Handler public void onExit(ExitEvent event) { + SWGObject object = event.object; + + if(object == null || !(object instanceof CreatureObject)) + return; + + CreatureObject creature = (CreatureObject) object; + + if(creature.getSlottedObject("ghost") == null) + return; + + creature.getEventBus().unsubscribe(this); + + } + + @Handler + public void onMove(MoveEvent event) { + + SWGObject object = event.object; + + if(object == null || !(object instanceof CreatureObject) || object.getContainer() != null) + return; + + CreatureObject creature = (CreatureObject) object; + + if(creature.getSlottedObject("ghost") == null) + return; + + if(new Random().nextFloat() <= 0.25) + spawnCreature(creature); + + } + + + private void spawnCreature(CreatureObject creature) { + + NGECore core = NGECore.getInstance(); + + Iterator it = mobiles.iterator(); + it.forEachRemaining(mobile -> { + if(mobile.getPosture() == Posture.Dead) + it.remove(); + }); + + if(mobiles.size() >= spawnGroup.getMaxSpawns()) + return; + + boolean foundPos = false; + int tries = 0; + Point3D randomPosition = null; + + while(!foundPos && ++tries < 10) { + + randomPosition = getRandomPosition(creature.getWorldPosition(), 32.f, 200.f); + + if(randomPosition == null) + return; + + TerrainService terrainSvc = core.terrainService; + + float height = terrainSvc.getHeight(getPlanet().getID(), randomPosition.x, randomPosition.z); + randomPosition.y = height; + + for(CreatureObject mobile : mobiles) { + if(mobile.getWorldPosition().getDistance(randomPosition) > spawnGroup.getMinSpawnDistance()) + foundPos = true; + } + + if(!terrainSvc.canBuildAtPosition(creature, randomPosition.x, randomPosition.z)) + foundPos = false; + + } + + if(!foundPos) + return; + + Random random = new Random(); + + String mobileTemplate = spawnGroup.getMobiles().get(random.nextInt(spawnGroup.getMobiles().size())); + CreatureObject spawnedCreature = core.spawnService.spawnCreature(mobileTemplate, getPlanet().getName(), 0, randomPosition.x, randomPosition.y, randomPosition.z); + if(spawnedCreature != null) + mobiles.add(spawnedCreature); + } } diff --git a/src/services/spawn/DynamicSpawnGroup.java b/src/services/spawn/DynamicSpawnGroup.java new file mode 100644 index 00000000..a29f6ae2 --- /dev/null +++ b/src/services/spawn/DynamicSpawnGroup.java @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 2013 + * + * This File is part of NGECore2. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + * + * Using NGEngine to work with NGECore2 is making a combined work based on NGEngine. + * Therefore all terms and conditions of the GNU Lesser General Public License cover the combination. + ******************************************************************************/ +package services.spawn; + +import java.util.Vector; + +public class DynamicSpawnGroup { + + private Vector mobiles; + private String name; + private int maxSpawns; + private int minSpawnDistance; + + public Vector getMobiles() { + return mobiles; + } + + public void setMobiles(Vector mobiles) { + this.mobiles = mobiles; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getMaxSpawns() { + return maxSpawns; + } + + public void setMaxSpawns(int maxSpawns) { + this.maxSpawns = maxSpawns; + } + + public int getMinSpawnDistance() { + return minSpawnDistance; + } + + public void setMinSpawnDistance(int minSpawnDistance) { + this.minSpawnDistance = minSpawnDistance; + } + +} diff --git a/src/services/spawn/LairSpawnArea.java b/src/services/spawn/LairSpawnArea.java index 026268cd..a4f29896 100644 --- a/src/services/spawn/LairSpawnArea.java +++ b/src/services/spawn/LairSpawnArea.java @@ -79,7 +79,7 @@ public class LairSpawnArea extends SpawnArea { randomPosition.y = height; for(LairActor otherLair : lairs) { - if(otherLair.getLairObject().getWorldPosition().getDistance(randomPosition) < 10) + if(otherLair.getLairObject().getWorldPosition().getDistance(randomPosition) < 30) return; } diff --git a/src/services/spawn/SpawnService.java b/src/services/spawn/SpawnService.java index dcde2707..b388cd47 100644 --- a/src/services/spawn/SpawnService.java +++ b/src/services/spawn/SpawnService.java @@ -61,6 +61,7 @@ public class SpawnService { private Map lairGroupTemplates = new ConcurrentHashMap(); private Map lairTemplates = new ConcurrentHashMap(); private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(4); + private Map dynamicGroupTemplates = new ConcurrentHashMap(); public SpawnService(NGECore core) { this.core = core; @@ -304,6 +305,26 @@ public class SpawnService { } } + public void loadDynamicGroups() { + Path p = Paths.get("scripts/mobiles/dynamicgroups"); + FileVisitor fv = new SimpleFileVisitor() { + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { + core.scriptService.callScript("scripts/mobiles/dynamicgroups/", file.getFileName().toString().replace(".py", ""), "addDynamicGroup", core); + return FileVisitResult.CONTINUE; + } + }; + try { + Files.walkFileTree(p, fv); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public void addDynamicGroup(String name, DynamicSpawnGroup dynamicSpawnGroup) { + dynamicGroupTemplates.put(name, dynamicSpawnGroup); + } + public void addLairGroup(String name, Vector lairSpawnTemplates) { lairGroupTemplates.put(name, new LairGroupTemplate(name, lairSpawnTemplates)); } @@ -334,6 +355,18 @@ public class SpawnService { spawnAreas.get(planet).add(lairSpawnArea); core.simulationService.addCollidable(collidableCircle, x, z); } + + public void addDynamicSpawnArea(String dynamicGroup, float x, float z, float radius, String planetName) { + DynamicSpawnGroup dynamicGroupTemplate = dynamicGroupTemplates .get(dynamicGroup); + Planet planet = core.terrainService.getPlanetByName(planetName); + if(dynamicGroupTemplate == null || planet == null) + return; + CollidableCircle collidableCircle = new CollidableCircle(new Point3D(x, 0, z), radius, planet); + DynamicSpawnArea dynamicSpawnArea = new DynamicSpawnArea(planet, collidableCircle, dynamicGroupTemplate); + spawnAreas.get(planet).add(dynamicSpawnArea); + core.simulationService.addCollidable(collidableCircle, x, z); + } + }