Repository navigation
Support for vehicle repair at Parking/Vehicle Garages #1832
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
madsboddum
wants to merge
2
commits into
ProjectSWGCore:master
Choose a base branch
from
madsboddum:vehicle-garages
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/main/java/com/projectswg/holocore/resources/gameplay/structures/VehicleGarages.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| /*********************************************************************************** | ||
| * Copyright (c) 2026 /// Project SWG /// www.projectswg.com * | ||
| * * | ||
| * ProjectSWG is an emulation project for Star Wars Galaxies founded on * | ||
| * July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. * | ||
| * Our goal is to create one or more emulators which will provide servers for * | ||
| * players to continue playing a game similar to the one they used to play. * | ||
| * * | ||
| * This file is part of Holocore. * | ||
| * * | ||
| * --------------------------------------------------------------------------------* | ||
| * * | ||
| * Holocore is free software: you can redistribute it and/or modify * | ||
| * it under the terms of the GNU Affero General Public License as * | ||
| * published by the Free Software Foundation, either version 3 of the * | ||
| * License, or (at your option) any later version. * | ||
| * * | ||
| * Holocore 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 Affero General Public License for more details. * | ||
| * * | ||
| * You should have received a copy of the GNU Affero General Public License * | ||
| * along with Holocore. If not, see <http://www.gnu.org/licenses/>. * | ||
| ***********************************************************************************/ | ||
| package com.projectswg.holocore.resources.gameplay.structures | ||
|
|
||
| import com.projectswg.holocore.resources.support.objects.swg.building.BuildingObject | ||
| import com.projectswg.holocore.resources.support.objects.swg.creature.CreatureObject | ||
|
|
||
| object VehicleGarages { | ||
|
|
||
| private const val RANGE = 64.0 | ||
|
|
||
| private val TEMPLATES = setOf( | ||
| "object/building/base/shared_base_parking_garage.iff", | ||
| "object/building/tatooine/shared_parking_garage_tatooine_style_1.iff", | ||
| "object/building/naboo/shared_parking_garage_naboo_style_1.iff", | ||
| "object/building/general/shared_parking_garage_general.iff", | ||
| "object/building/corellia/shared_garage_corellia.iff", | ||
| "object/building/player/shared_player_garage_tatooine_style_01.iff", | ||
| "object/building/player/shared_player_garage_naboo_style_01.iff", | ||
| "object/building/player/shared_player_garage_corellia_style_01.iff", | ||
| ) | ||
|
|
||
| @JvmStatic | ||
| fun nearestGarage(player: CreatureObject): BuildingObject? { | ||
| val playerLocation = player.worldLocation | ||
| return player.aware.asSequence() | ||
| .filterIsInstance<BuildingObject>() | ||
| .filter { it.template in TEMPLATES } | ||
| .minByOrNull { it.worldLocation.flatDistanceTo(playerLocation) } | ||
| ?.takeIf { it.worldLocation.flatDistanceTo(playerLocation) <= RANGE } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
162 changes: 162 additions & 0 deletions
162
src/main/java/com/projectswg/holocore/services/gameplay/structures/VehicleGarageService.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,162 @@ | ||
| /*********************************************************************************** | ||
| * Copyright (c) 2026 /// Project SWG /// www.projectswg.com * | ||
| * * | ||
| * ProjectSWG is an emulation project for Star Wars Galaxies founded on * | ||
| * July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. * | ||
| * Our goal is to create one or more emulators which will provide servers for * | ||
| * players to continue playing a game similar to the one they used to play. * | ||
| * * | ||
| * This file is part of Holocore. * | ||
| * * | ||
| * --------------------------------------------------------------------------------* | ||
| * * | ||
| * Holocore is free software: you can redistribute it and/or modify * | ||
| * it under the terms of the GNU Affero General Public License as * | ||
| * published by the Free Software Foundation, either version 3 of the * | ||
| * License, or (at your option) any later version. * | ||
| * * | ||
| * Holocore 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 Affero General Public License for more details. * | ||
| * * | ||
| * You should have received a copy of the GNU Affero General Public License * | ||
| * along with Holocore. If not, see <http://www.gnu.org/licenses/>. * | ||
| ***********************************************************************************/ | ||
| package com.projectswg.holocore.services.gameplay.structures | ||
|
|
||
| import com.projectswg.common.data.encodables.oob.ProsePackage | ||
| import com.projectswg.common.data.encodables.oob.StringId | ||
| import com.projectswg.holocore.intents.gameplay.world.RepairVehicleIntent | ||
| import com.projectswg.holocore.intents.gameplay.world.StoreMountIntent | ||
| import com.projectswg.holocore.intents.support.global.chat.SystemMessageIntent | ||
| import com.projectswg.holocore.intents.support.global.chat.SystemMessageIntent.Companion.broadcastPersonal | ||
| import com.projectswg.holocore.intents.support.global.zone.PlayerEventIntent | ||
| import com.projectswg.holocore.intents.support.global.zone.PlayerTransformedIntent | ||
| import com.projectswg.holocore.resources.gameplay.structures.VehicleGarages.nearestGarage | ||
| import com.projectswg.holocore.resources.support.data.server_info.StandardLog | ||
| import com.projectswg.holocore.resources.support.data.server_info.loader.DataLoader.Companion.vehicles | ||
| import com.projectswg.holocore.resources.support.data.server_info.loader.VehicleLoader.VehicleInfo | ||
| import com.projectswg.holocore.resources.support.global.player.PlayerEvent | ||
| import com.projectswg.holocore.resources.support.global.zone.sui.SuiButtons | ||
| import com.projectswg.holocore.resources.support.global.zone.sui.SuiListBox | ||
| import com.projectswg.holocore.resources.support.objects.swg.creature.CreatureObject | ||
| import com.projectswg.holocore.resources.support.objects.swg.creature.CreatureState | ||
| import me.joshlarson.jlcommon.control.IntentHandler | ||
| import me.joshlarson.jlcommon.control.Service | ||
| import java.util.concurrent.ConcurrentHashMap | ||
| import kotlin.math.roundToInt | ||
| import kotlin.math.roundToLong | ||
|
|
||
| class VehicleGarageService : Service() { | ||
|
|
||
| private val playersNotifiedOfGarage: MutableSet<CreatureObject> = ConcurrentHashMap.newKeySet() | ||
|
|
||
| @IntentHandler | ||
| private fun handlePlayerTransformedIntent(pti: PlayerTransformedIntent) { | ||
| val player = pti.player | ||
| if (!player.isStatesBitmask(CreatureState.RIDING_MOUNT)) return | ||
| val owner = player.owner ?: return | ||
|
|
||
| if (nearestGarage(player) != null) { | ||
| if (playersNotifiedOfGarage.add(player)) broadcastPersonal(owner, "@pet/pet_menu:garage_proximity") | ||
| } else { | ||
| playersNotifiedOfGarage.remove(player) | ||
| } | ||
| } | ||
|
|
||
| @IntentHandler | ||
| private fun handleStoreMountIntent(smi: StoreMountIntent) { | ||
| playersNotifiedOfGarage.remove(smi.creature) | ||
| } | ||
|
|
||
| @IntentHandler | ||
| private fun handlePlayerEventIntent(pei: PlayerEventIntent) { | ||
| if (pei.event == PlayerEvent.PE_DISAPPEAR) playersNotifiedOfGarage.remove(pei.player.creatureObject) | ||
| } | ||
|
|
||
| @IntentHandler | ||
| private fun handleRepairVehicleIntent(rvi: RepairVehicleIntent) { | ||
| val creature = rvi.creature | ||
| val mount = rvi.pet | ||
| val owner = creature.owner ?: return | ||
|
|
||
| if (creature.objectId != mount.ownerId) return | ||
| if (nearestGarage(creature) == null) { | ||
| broadcastPersonal(owner, "@pet/pet_menu:repair_unrecognized_garages") | ||
| return | ||
| } | ||
|
|
||
| val damage = mount.conditionDamage | ||
| if (damage <= 0) { | ||
| broadcastPersonal(owner, "@pet/pet_menu:undamaged_vehicle") | ||
| return | ||
| } | ||
|
|
||
| val vehicleInfo = vehicles().getVehicleFromIff(mount.template) | ||
| if (vehicleInfo == null || vehicleInfo.repairRate <= 0) { | ||
| StandardLog.onPlayerError(this, creature, "unable to determine repair rate for vehicle %s", mount) | ||
| broadcastPersonal(owner, "@pet/pet_menu:repair_error") | ||
| return | ||
| } | ||
|
|
||
| if (damage >= mount.maxHitPoints && !vehicleInfo.isCanRepairDisabled) { | ||
| broadcastPersonal(owner, "@pet/pet_menu:cannot_repair_disabled") | ||
| return | ||
| } | ||
|
|
||
| val cost = repairCost(damage, vehicleInfo.repairRate) | ||
| val funds = creature.bankBalance | ||
| if (funds < cost) { | ||
| broadcastPersonal(owner, lackingFunds(cost - funds)) | ||
| return | ||
| } | ||
|
|
||
| SuiListBox().run { | ||
| title = "@pet/pet_menu:confirm_repairs_t" | ||
| prompt = "@pet/pet_menu:vehicle_repair_d" | ||
| buttons = SuiButtons.OK_CANCEL | ||
| addListItem("@pet/pet_menu:vehicle_prompt ${mount.stringId}") | ||
| addListItem("@pet/pet_menu:repair_cost_prompt $cost") | ||
| addListItem("@pet/pet_menu:total_funds_prompt $funds") | ||
| addOkButtonCallback("repair") { _, _ -> repair(creature, mount, cost, vehicleInfo) } | ||
| display(owner) | ||
| } | ||
| } | ||
|
|
||
| private fun repair(creature: CreatureObject, mount: CreatureObject, cost: Long, vehicleInfo: VehicleInfo) { | ||
| val owner = creature.owner ?: return | ||
|
|
||
| if (nearestGarage(creature) == null) { | ||
| broadcastPersonal(owner, "@pet/pet_menu:garage_out_of_range") | ||
| return | ||
| } | ||
|
|
||
| val funds = creature.bankBalance | ||
| if (!creature.removeFromBank(cost)) { | ||
| broadcastPersonal(owner, lackingFunds(cost - funds)) | ||
| return | ||
| } | ||
|
|
||
| val damage = mount.conditionDamage | ||
| val paidForPoints = (cost / vehicleInfo.repairRate).roundToInt() | ||
| val repairedPoints = paidForPoints.coerceAtMost(damage) | ||
| var paid = cost | ||
|
|
||
| // Condition may have improved between opening the window and confirming - only charge for what's actually repaired | ||
| if (repairedPoints < paidForPoints) { | ||
| paid = repairCost(repairedPoints, vehicleInfo.repairRate) | ||
| creature.addToBank(cost - paid) | ||
| SystemMessageIntent.broadcastPersonal(owner, ProsePackage(StringId("pet/pet_menu", "repair_condition_changed"), "DI", paid.toInt())) | ||
| } | ||
|
|
||
| SystemMessageIntent.broadcastPersonal(owner, ProsePackage(StringId("base_player", "prose_pay_success_no_target"), "DI", paid.toInt())) | ||
|
|
||
| mount.conditionDamage = damage - repairedPoints | ||
| StandardLog.onPlayerEvent(this, creature, "repaired mount %s for %d credits, condition is now %d/%d", mount, paid, mount.maxHitPoints - mount.conditionDamage, mount.maxHitPoints) | ||
| } | ||
|
|
||
| private fun repairCost(points: Int, repairRate: Double): Long = (points * repairRate).roundToLong() | ||
|
|
||
| private fun lackingFunds(missing: Long): String = "@pet/pet_menu:lacking_funds_prefix $missing @pet/pet_menu:lacking_funds_suffix" | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't really be scanning the entire awareness of a player every time they move/rotate. Need to hook into the on awareness changed functionality in each CreatureObject somehow. I'm leaning towards an intent notifying on player awareness changed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, this would be much more efficient.