Refactored radial system

This commit is contained in:
Obique
2018-02-11 13:21:51 -06:00
parent b567f6e5a4
commit 02b45f4b8e
32 changed files with 2136 additions and 2135 deletions
+2 -2
View File
@@ -17,8 +17,8 @@ plugins {
}
mainClassName = 'com.projectswg.holocore.ProjectSWG'
sourceCompatibility = 1.9
targetCompatibility = 1.9
sourceCompatibility = 9
targetCompatibility = 9
test {
testLogging {
-20
View File
@@ -1,20 +0,0 @@
iff script
TEXT TEXT
object/tangible/terminal/shared_terminal_bank.iff terminal/bank
object/tangible/terminal/shared_terminal_bazaar.iff terminal/bazaar
object/tangible/terminal/shared_terminal_travel.iff terminal/travel
object/tangible/travel/ticket_collector/shared_ticket_collector.iff terminal/ticket_collector
object/tangible/travel/travel_ticket/base/shared_base_travel_ticket.iff terminal/ticket
object/tangible/npe/shared_npe_uniform_box.iff object/usable
object/tangible/terminal/shared_terminal_character_builder.iff terminal/character_builder
object/tangible/survey_tool/shared_survey_tool_all.iff object/survey/survey_tool
object/tangible/survey_tool/shared_survey_tool_gas.iff object/survey/survey_tool
object/tangible/survey_tool/shared_survey_tool_geo_thermal.iff object/survey/survey_tool
object/tangible/survey_tool/shared_survey_tool_inorganic.iff object/survey/survey_tool
object/tangible/survey_tool/shared_survey_tool_liquid.iff object/survey/survey_tool
object/tangible/survey_tool/shared_survey_tool_lumber.iff object/survey/survey_tool
object/tangible/survey_tool/shared_survey_tool_mineral.iff object/survey/survey_tool
object/tangible/survey_tool/shared_survey_tool_moisture.iff object/survey/survey_tool
object/tangible/survey_tool/shared_survey_tool_organic.iff object/survey/survey_tool
object/tangible/survey_tool/shared_survey_tool_solar.iff object/survey/survey_tool
object/tangible/survey_tool/shared_survey_tool_wind.iff object/survey/survey_tool
@@ -0,0 +1,116 @@
/***********************************************************************************
* Copyright (c) 2018 /// Project SWG /// www.projectswg.com *
* *
* ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on *
* July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. *
* Our goal is to create an emulator which will provide a server for players to *
* continue playing a game similar to the one they used to play. We are basing *
* it on the final publish of the game prior to end-game events. *
* *
* 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.scripts.radial
import com.projectswg.common.data.radial.RadialItem
import com.projectswg.common.data.radial.RadialOption
import com.projectswg.holocore.resources.objects.SWGObject
import com.projectswg.holocore.resources.objects.custom.AIObject
import com.projectswg.holocore.resources.objects.tangible.CreditObject
import com.projectswg.holocore.resources.player.Player
import com.projectswg.holocore.scripts.radial.object.AIObjectRadial
import com.projectswg.holocore.scripts.radial.object.CreditObjectRadial
import com.projectswg.holocore.scripts.radial.object.SWGObjectRadial
import com.projectswg.holocore.scripts.radial.object.UsableObjectRadial
import com.projectswg.holocore.scripts.radial.object.survey.ObjectSurveyToolRadial
import com.projectswg.holocore.scripts.radial.object.uniform.ObjectUniformBoxRadial
import com.projectswg.holocore.scripts.radial.terminal.*
import javax.annotation.Nonnull
class RadialHandler {
private static Map<String, RadialHandlerInterface> handlers = new HashMap<>()
private static Map<Class<? extends SWGObject>, RadialHandlerInterface> classHandlers = new HashMap<>()
private static SWGObjectRadial genericRadialHandler = new SWGObjectRadial()
static def initialize() {
initializeTerminalRadials()
initializeSurveyRadials()
initializeMiscRadials()
classHandlers.put(AIObject.class, new AIObjectRadial())
classHandlers.put(CreditObject.class, new CreditObjectRadial())
}
static def registerHandler(String iff, RadialHandlerInterface handler) {
handlers.put(iff, handler)
}
static def getOptions(List<RadialOption> options, Player player, SWGObject target) {
getHandler(target).getOptions(options, player, target)
}
static def handleSelection(Player player, SWGObject target, RadialItem selection) {
getHandler(target).handleSelection(player, target, selection)
}
@Nonnull
private static def getHandler(SWGObject target) {
def type = target.getTemplate()
RadialHandlerInterface handler = handlers.get(type)
if (handler != null)
return handler
if (target != null) {
handler = classHandlers.get(target.getClass())
if (handler != null)
return handler
}
return genericRadialHandler
}
private static def initializeTerminalRadials() {
registerHandler("object/tangible/terminal/shared_terminal_bank.iff", new TerminalBankRadial())
registerHandler("object/tangible/terminal/shared_terminal_bazaar.iff", new TerminalBazaarRadial())
registerHandler("object/tangible/terminal/shared_terminal_travel.iff", new TerminalTravelRadial())
registerHandler("object/tangible/travel/ticket_collector/shared_ticket_collector.iff", new TerminalTicketCollectorRadial())
registerHandler("object/tangible/travel/travel_ticket/base/shared_base_travel_ticket.iff", new TerminalTicketRadial())
}
private static def initializeSurveyRadials() {
registerHandler("object/tangible/survey_tool/shared_survey_tool_all.iff", new ObjectSurveyToolRadial())
registerHandler("object/tangible/survey_tool/shared_survey_tool_gas.iff", new ObjectSurveyToolRadial())
registerHandler("object/tangible/survey_tool/shared_survey_tool_geo_thermal.iff", new ObjectSurveyToolRadial())
registerHandler("object/tangible/survey_tool/shared_survey_tool_inorganic.iff", new ObjectSurveyToolRadial())
registerHandler("object/tangible/survey_tool/shared_survey_tool_liquid.iff", new ObjectSurveyToolRadial())
registerHandler("object/tangible/survey_tool/shared_survey_tool_lumber.iff", new ObjectSurveyToolRadial())
registerHandler("object/tangible/survey_tool/shared_survey_tool_mineral.iff", new ObjectSurveyToolRadial())
registerHandler("object/tangible/survey_tool/shared_survey_tool_moisture.iff", new ObjectSurveyToolRadial())
registerHandler("object/tangible/survey_tool/shared_survey_tool_organic.iff", new ObjectSurveyToolRadial())
registerHandler("object/tangible/survey_tool/shared_survey_tool_solar.iff", new ObjectSurveyToolRadial())
registerHandler("object/tangible/survey_tool/shared_survey_tool_wind.iff", new ObjectSurveyToolRadial())
}
private static def initializeMiscRadials() {
registerHandler("object/tangible/npe/shared_npe_uniform_box.iff", new UsableObjectRadial())
registerHandler("object/tangible/terminal/shared_terminal_character_builder.iff", new TerminalCharacterBuilderRadial())
registerHandler("object/tangible/npe/shared_npe_uniform_box.iff", new ObjectUniformBoxRadial())
}
}
@@ -0,0 +1,38 @@
/***********************************************************************************
* Copyright (c) 2018 /// Project SWG /// www.projectswg.com *
* *
* ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on *
* July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. *
* Our goal is to create an emulator which will provide a server for players to *
* continue playing a game similar to the one they used to play. We are basing *
* it on the final publish of the game prior to end-game events. *
* *
* 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.scripts.radial
import com.projectswg.common.data.radial.RadialItem
import com.projectswg.common.data.radial.RadialOption
import com.projectswg.holocore.resources.objects.SWGObject
import com.projectswg.holocore.resources.player.Player
interface RadialHandlerInterface {
def getOptions(List<RadialOption> options, Player player, SWGObject target)
def handleSelection(Player player, SWGObject target, RadialItem selection)
}
@@ -29,18 +29,41 @@ package com.projectswg.holocore.scripts.radial.collection
import com.projectswg.common.data.radial.RadialItem
import com.projectswg.common.data.radial.RadialOption
import com.projectswg.holocore.intents.GrantClickyCollectionIntent
import com.projectswg.holocore.resources.objects.SWGObject
import com.projectswg.holocore.resources.objects.collections.CollectionItem
import com.projectswg.holocore.resources.player.Player
import com.projectswg.holocore.scripts.radial.RadialHandlerInterface
static def getOptions(List<RadialOption> options, Player player, SWGObject target, Object... args) {
options.add(new RadialOption(RadialItem.ITEM_USE))
options.get(0).setOverriddenText("@collection:consume_item")
}
static def handleSelection(Player player, SWGObject target, RadialItem selection, Object... args) {
switch (selection) {
case RadialItem.ITEM_USE:
//Log.d("bazaar.groovy", "Bazaar Selection: ITEM_USE")
break
class WorldItemRadial implements RadialHandlerInterface {
private final CollectionItem details
WorldItemRadial(CollectionItem details) {
this.details = details
}
def getOptions(List<RadialOption> options, Player player, SWGObject target) {
def use = null
for (RadialOption option : options) {
if (option.getOptionType() == RadialItem.ITEM_USE.getId()) {
use = option
break
}
}
if (use == null) {
use = new RadialOption(RadialItem.ITEM_USE)
options.add(0, use)
}
use.setOverriddenText("@collection:consume_item")
}
def handleSelection(Player player, SWGObject target, RadialItem selection) {
if (selection != RadialItem.ITEM_USE)
return
new GrantClickyCollectionIntent(player.getCreatureObject(), target, details).broadcast();
}
}
@@ -0,0 +1,55 @@
/***********************************************************************************
* Copyright (c) 2018 /// Project SWG /// www.projectswg.com *
* *
* ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on *
* July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. *
* Our goal is to create an emulator which will provide a server for players to *
* continue playing a game similar to the one they used to play. We are basing *
* it on the final publish of the game prior to end-game events. *
* *
* 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.scripts.radial.object
import com.projectswg.common.data.radial.RadialItem
import com.projectswg.common.data.radial.RadialOption
import com.projectswg.holocore.intents.combat.loot.LootRequestIntent
import com.projectswg.holocore.resources.objects.SWGObject
import com.projectswg.holocore.resources.player.Player
import com.projectswg.holocore.scripts.radial.RadialHandlerInterface
class AIObjectRadial extends SWGObjectRadial implements RadialHandlerInterface {
def getOptions(List<RadialOption> options, Player player, SWGObject target) {
RadialOption loot = new RadialOption(RadialItem.LOOT)
loot.addChild(RadialItem.LOOT_ALL)
options.add(loot)
}
def handleSelection(Player player, SWGObject target, RadialItem selection) {
switch (selection) {
case RadialItem.LOOT:
LootRequestIntent.broadcast(player, target, LootRequestIntent.LootType.LOOT)
break
case RadialItem.LOOT_ALL:
LootRequestIntent.broadcast(player, target, LootRequestIntent.LootType.LOOT_ALL)
break
}
}
}
@@ -0,0 +1,46 @@
/***********************************************************************************
* Copyright (c) 2018 /// Project SWG /// www.projectswg.com *
* *
* ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on *
* July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. *
* Our goal is to create an emulator which will provide a server for players to *
* continue playing a game similar to the one they used to play. We are basing *
* it on the final publish of the game prior to end-game events. *
* *
* 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.scripts.radial.object
import com.projectswg.common.data.radial.RadialItem
import com.projectswg.common.data.radial.RadialOption
import com.projectswg.holocore.intents.combat.loot.LootRequestIntent
import com.projectswg.holocore.resources.objects.SWGObject
import com.projectswg.holocore.resources.player.Player
import com.projectswg.holocore.scripts.radial.RadialHandlerInterface
class CreditObjectRadial extends SWGObjectRadial implements RadialHandlerInterface {
def getOptions(List<RadialOption> options, Player player, SWGObject target) {
options.add(new RadialOption(RadialItem.TRANSFER_CREDITS_TO_BANK_ACCOUNT))
}
def handleSelection(Player player, SWGObject target, RadialItem selection) {
LootRequestIntent.broadcast(player, target, LootRequestIntent.LootType.CREDITS)
}
}
@@ -31,11 +31,16 @@ import com.projectswg.common.data.radial.RadialItem
import com.projectswg.common.data.radial.RadialOption
import com.projectswg.holocore.resources.objects.SWGObject
import com.projectswg.holocore.resources.player.Player
import com.projectswg.holocore.scripts.radial.RadialHandlerInterface
static def getOptions(List<RadialOption> options, Player player, SWGObject target, Object... args) {
options.add(new RadialOption(RadialItem.ITEM_USE))
options.add(new RadialOption(RadialItem.EXAMINE))
}
static def handleSelection(Player player, SWGObject target, RadialItem selection, Object... args) {
class SWGObjectRadial implements RadialHandlerInterface {
def getOptions(List<RadialOption> options, Player player, SWGObject target) {
}
def handleSelection(Player player, SWGObject target, RadialItem selection) {
}
}
@@ -0,0 +1,42 @@
/***********************************************************************************
* Copyright (c) 2018 /// Project SWG /// www.projectswg.com *
* *
* ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on *
* July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. *
* Our goal is to create an emulator which will provide a server for players to *
* continue playing a game similar to the one they used to play. We are basing *
* it on the final publish of the game prior to end-game events. *
* *
* 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.scripts.radial.object
import com.projectswg.common.data.radial.RadialItem
import com.projectswg.common.data.radial.RadialOption
import com.projectswg.holocore.resources.objects.SWGObject
import com.projectswg.holocore.resources.player.Player
class UsableObjectRadial extends SWGObjectRadial {
def getOptions(List<RadialOption> options, Player player, SWGObject target) {
options.add(new RadialOption(RadialItem.ITEM_USE))
options.add(new RadialOption(RadialItem.EXAMINE))
}
}
@@ -32,12 +32,17 @@ import com.projectswg.common.data.radial.RadialOption
import com.projectswg.holocore.intents.crafting.survey.StartSurveyToolIntent
import com.projectswg.holocore.resources.objects.SWGObject
import com.projectswg.holocore.resources.player.Player
import com.projectswg.holocore.scripts.radial.RadialHandlerInterface
static def getOptions(List<RadialOption> options, Player player, SWGObject target, Object... args) {
options.add(new RadialOption(RadialItem.ITEM_USE))
options.add(new RadialOption(RadialItem.EXAMINE))
}
static def handleSelection(Player player, SWGObject target, RadialItem selection, Object... args) {
new StartSurveyToolIntent(player.getCreatureObject(), target).broadcast()
class ObjectSurveyToolRadial implements RadialHandlerInterface {
def getOptions(List<RadialOption> options, Player player, SWGObject target) {
options.add(new RadialOption(RadialItem.ITEM_USE))
options.add(new RadialOption(RadialItem.EXAMINE))
}
def handleSelection(Player player, SWGObject target, RadialItem selection) {
new StartSurveyToolIntent(player.getCreatureObject(), target).broadcast()
}
}
@@ -0,0 +1,44 @@
/***********************************************************************************
* Copyright (c) 2018 /// Project SWG /// www.projectswg.com *
* *
* ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on *
* July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. *
* Our goal is to create an emulator which will provide a server for players to *
* continue playing a game similar to the one they used to play. We are basing *
* it on the final publish of the game prior to end-game events. *
* *
* 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.scripts.radial.object.uniform
import com.projectswg.common.data.radial.RadialItem
import com.projectswg.holocore.intents.object.DestroyObjectIntent
import com.projectswg.holocore.intents.player.uniform.OpenUniformBoxIntent
import com.projectswg.holocore.resources.objects.SWGObject
import com.projectswg.holocore.resources.player.Player
import com.projectswg.holocore.scripts.radial.RadialHandlerInterface
import com.projectswg.holocore.scripts.radial.object.SWGObjectRadial
class ObjectUniformBoxRadial extends SWGObjectRadial implements RadialHandlerInterface {
def handleSelection(Player player, SWGObject target, RadialItem selection) {
DestroyObjectIntent.broadcast(target)
OpenUniformBoxIntent.broadcast(player)
}
}
@@ -36,113 +36,146 @@ import com.projectswg.holocore.resources.objects.creature.CreatureObject
import com.projectswg.holocore.resources.player.Player
import com.projectswg.holocore.resources.sui.SuiButtons
import com.projectswg.holocore.resources.sui.SuiWindow
import com.projectswg.holocore.scripts.radial.RadialHandlerInterface
import com.projectswg.holocore.utilities.IntentFactory
static def getOptions(List<RadialOption> options, Player player, SWGObject target) {
def use = new RadialOption(RadialItem.ITEM_USE)
def reserve = new RadialOption(RadialItem.SERVER_MENU50)
def creature = player.getCreatureObject()
reserve.setOverriddenText("@sui:bank_galactic_reserve")
options.add(use)
options.add(new RadialOption(RadialItem.EXAMINE))
if (creature.getCurrentCity() == "@corellia_region_names:coronet" ||
creature.getCurrentCity() == "@naboo_region_names:theed" ||
creature.getCurrentCity() == "@tatooine_region_names:mos_eisley")
options.add(reserve)
// Bank Transfer/Safety Deposit
use.addChildWithOverriddenText(RadialItem.SERVER_MENU1, "@sui:bank_credits")
use.addChildWithOverriddenText(RadialItem.SERVER_MENU2, "@sui:bank_items")
// Withdraw/Deposit
if (creature.getBankBalance() > 0)
use.addChildWithOverriddenText(RadialItem.SERVER_MENU4, "@sui:bank_withdrawall")
if (creature.getCashBalance() > 0)
use.addChildWithOverriddenText(RadialItem.SERVER_MENU3, "@sui:bank_depositall")
// Galactic Reserve
if (creature.getBankBalance() >= 1E9 || creature.getCashBalance() >= 1E9)
reserve.addChildWithOverriddenText(RadialItem.SERVER_MENU49, "@sui:bank_galactic_reserve_deposit")
if (creature.getReserveBalance() > 0)
reserve.addChildWithOverriddenText(RadialItem.SERVER_MENU48, "@sui:bank_galactic_reserve_withdraw")
}
static def handleSelection(Player player, SWGObject target, RadialItem selection) {
def creature = player.getCreatureObject()
switch (selection) {
case RadialItem.ITEM_USE:
case RadialItem.SERVER_MENU1:
def window = new SuiWindow("Script.transfer", SuiButtons.OK_CANCEL, '@base_player:bank_title', '@base_player:bank_prompt')
window.setPropertyText('transaction.lblFrom', 'Cash')
window.setPropertyText('transaction.lblTo', 'Bank')
window.setPropertyText('transaction.lblStartingFrom', creature.getCashBalance().toString())
window.setPropertyText('transaction.lblStartingTo', creature.getBankBalance().toString())
window.setPropertyText('transaction.txtInputFrom', creature.getCashBalance().toString())
window.setPropertyText('transaction.txtInputTo', creature.getBankBalance().toString())
window.setProperty('transaction', 'ConversionRatioFrom', '1')
window.setProperty('transaction', 'ConversionRatioTo', '1')
window.addReturnableProperty('transaction.txtInputFrom', 'Text')
window.addReturnableProperty('transaction.txtInputTo', 'Text')
window.addCallback(SuiEvent.OK_PRESSED, "handleBankTransfer", {event,parameters -> handleBankTransfer(player, player.getCreatureObject(), parameters)})
window.display(player)
break
case RadialItem.SERVER_MENU2:
player.sendPacket(new ClientOpenContainerMessage(creature.getSlottedObject("bank").getObjectId(), ""))
break
case RadialItem.SERVER_MENU4:
def amount = creature.getBankBalance() as long
creature.setCashBalance(creature.getCashBalance() + amount)
creature.setBankBalance(0l)
if (amount > 0)
IntentFactory.sendSystemMessage(player, "@base_player:prose_withdraw_success", "DI", (int) amount)
else
IntentFactory.sendSystemMessage(player, '@error_message:bank_withdraw')
break
case RadialItem.SERVER_MENU3:
def amount = creature.getCashBalance() as long
creature.setBankBalance(amount + creature.getBankBalance())
creature.setCashBalance(0l)
if (amount > 0)
IntentFactory.sendSystemMessage(player, "@base_player:prose_deposit_success", "DI", (int) amount)
else
IntentFactory.sendSystemMessage(player, '@error_message:bank_deposit')
break
case RadialItem.SERVER_MENU49:
if (!creature.canPerformGalacticReserveTransaction()) {
IntentFactory.sendSystemMessage(player, "You have to wait to perform another Galactic Reserve transaction")
class TerminalBankRadial implements RadialHandlerInterface {
def getOptions(List<RadialOption> options, Player player, SWGObject target) {
def use = new RadialOption(RadialItem.ITEM_USE)
def creature = player.getCreatureObject()
options.add(use)
options.add(new RadialOption(RadialItem.EXAMINE))
// Bank Transfer/Safety Deposit
use.addChildWithOverriddenText(RadialItem.SERVER_MENU1, "@sui:bank_credits")
use.addChildWithOverriddenText(RadialItem.SERVER_MENU2, "@sui:bank_items")
// Withdraw/Deposit
if (creature.getBankBalance() > 0)
use.addChildWithOverriddenText(RadialItem.SERVER_MENU4, "@sui:bank_withdrawall")
if (creature.getCashBalance() > 0)
use.addChildWithOverriddenText(RadialItem.SERVER_MENU3, "@sui:bank_depositall")
if (isInGalacticReserveCity(creature)) {
def reserve = new RadialOption(RadialItem.SERVER_MENU50)
reserve.setOverriddenText("@sui:bank_galactic_reserve")
if (creature.getBankBalance() >= 1E9 || creature.getCashBalance() >= 1E9)
reserve.addChildWithOverriddenText(RadialItem.SERVER_MENU49, "@sui:bank_galactic_reserve_deposit")
if (creature.getReserveBalance() > 0)
reserve.addChildWithOverriddenText(RadialItem.SERVER_MENU48, "@sui:bank_galactic_reserve_withdraw")
options.add(reserve)
}
}
def handleSelection(Player player, SWGObject target, RadialItem selection) {
def creature = player.getCreatureObject()
switch (selection) {
case RadialItem.ITEM_USE:
case RadialItem.SERVER_MENU1:
handleTransfer(player, creature)
break
}
def amount = creature.getBankBalance() as long
if (amount > 1E9)
amount = 1E9
if (creature.getReserveBalance() + amount > 3E9 || amount == 0) {
IntentFactory.sendSystemMessage(player, '@error_message:bank_deposit')
case RadialItem.SERVER_MENU2:
handleOpenBank(player, creature)
break
}
creature.setBankBalance((creature.getBankBalance() - amount).longValue())
creature.setReserveBalance((creature.getReserveBalance() + amount).longValue())
creature.updateLastGalacticReserveTime()
break
case RadialItem.SERVER_MENU48:
if (!creature.canPerformGalacticReserveTransaction()) {
IntentFactory.sendSystemMessage(player, "You have to wait to perform another Galactic Reserve transaction")
case RadialItem.SERVER_MENU3:
handleBankDeposit(player, creature)
break
}
def amount = creature.getReserveBalance()
if (amount > 1E9)
amount = 1E9
if (creature.getBankBalance() + amount > 2E9 || amount == 0) {
IntentFactory.sendSystemMessage(player, '@error_message:bank_withdraw')
case RadialItem.SERVER_MENU4:
handleBankWithdraw(player, creature)
break
}
creature.setBankBalance((creature.getBankBalance() + amount).longValue())
creature.setReserveBalance((creature.getReserveBalance() - amount).longValue())
creature.updateLastGalacticReserveTime()
break
case RadialItem.SERVER_MENU49:
handleGalacticReserveDeposit(player, creature)
break
case RadialItem.SERVER_MENU48:
handleGalacticReserveWithdraw(player, creature)
break
}
}
static def handleTransfer(Player player, CreatureObject creature) {
def window = new SuiWindow("Script.transfer", SuiButtons.OK_CANCEL, '@base_player:bank_title', '@base_player:bank_prompt')
window.setPropertyText('transaction.lblFrom', 'Cash')
window.setPropertyText('transaction.lblTo', 'Bank')
window.setPropertyText('transaction.lblStartingFrom', creature.getCashBalance().toString())
window.setPropertyText('transaction.lblStartingTo', creature.getBankBalance().toString())
window.setPropertyText('transaction.txtInputFrom', creature.getCashBalance().toString())
window.setPropertyText('transaction.txtInputTo', creature.getBankBalance().toString())
window.setProperty('transaction', 'ConversionRatioFrom', '1')
window.setProperty('transaction', 'ConversionRatioTo', '1')
window.addReturnableProperty('transaction.txtInputFrom', 'Text')
window.addReturnableProperty('transaction.txtInputTo', 'Text')
window.addCallback(SuiEvent.OK_PRESSED, "handleBankTransfer", {event,parameters -> handleBankTransfer(player, player.getCreatureObject(), parameters)})
window.display(player)
}
static def handleOpenBank(Player player, CreatureObject creature) {
player.sendPacket(new ClientOpenContainerMessage(creature.getSlottedObject("bank").getObjectId(), ""))
}
static def handleBankDeposit(Player player, CreatureObject creature) {
def amount = creature.getCashBalance() as long
creature.setBankBalance(amount + creature.getBankBalance())
creature.setCashBalance(0l)
if (amount > 0)
IntentFactory.sendSystemMessage(player, "@base_player:prose_deposit_success", "DI", (int) amount)
else
IntentFactory.sendSystemMessage(player, '@error_message:bank_deposit')
}
static def handleBankWithdraw(Player player, CreatureObject creature) {
def amount = creature.getBankBalance() as long
creature.setCashBalance(creature.getCashBalance() + amount)
creature.setBankBalance(0l)
if (amount > 0)
IntentFactory.sendSystemMessage(player, "@base_player:prose_withdraw_success", "DI", (int) amount)
else
IntentFactory.sendSystemMessage(player, '@error_message:bank_withdraw')
}
static def isInGalacticReserveCity(CreatureObject creature) {
return creature.getCurrentCity() == "@corellia_region_names:coronet" || creature.getCurrentCity() == "@naboo_region_names:theed" || creature.getCurrentCity() == "@tatooine_region_names:mos_eisley"
}
static def handleGalacticReserveDeposit(Player player, CreatureObject creature) {
if (!creature.canPerformGalacticReserveTransaction()) {
IntentFactory.sendSystemMessage(player, "You have to wait to perform another Galactic Reserve transaction")
return
}
def amount = creature.getBankBalance() as long
if (amount > 1E9)
amount = 1E9
if (creature.getReserveBalance() + amount > 3E9 || amount == 0) {
IntentFactory.sendSystemMessage(player, '@error_message:bank_deposit')
return
}
creature.setBankBalance((creature.getBankBalance() - amount).longValue())
creature.setReserveBalance((creature.getReserveBalance() + amount).longValue())
creature.updateLastGalacticReserveTime()
}
static def handleGalacticReserveWithdraw(Player player, CreatureObject creature) {
if (!creature.canPerformGalacticReserveTransaction()) {
IntentFactory.sendSystemMessage(player, "You have to wait to perform another Galactic Reserve transaction")
return
}
def amount = creature.getReserveBalance()
if (amount > 1E9)
amount = 1E9
if (creature.getBankBalance() + amount > 2E9 || amount == 0) {
IntentFactory.sendSystemMessage(player, '@error_message:bank_withdraw')
return
}
creature.setBankBalance((creature.getBankBalance() + amount).longValue())
creature.setReserveBalance((creature.getReserveBalance() - amount).longValue())
creature.updateLastGalacticReserveTime()
}
static def handleBankTransfer(Player player, CreatureObject creature, Map<String, String> parameters) {
creature.setCashBalance(Long.parseLong(parameters.get('transaction.txtInputFrom.Text')))
creature.setBankBalance(Long.parseLong(parameters.get('transaction.txtInputTo.Text')))
IntentFactory.sendSystemMessage(player, '@base_player:bank_success')
}
}
static def handleBankTransfer(Player player, CreatureObject creature, Map<String, String> parameters) {
creature.setCashBalance(Long.parseLong(parameters.get('transaction.txtInputFrom.Text')))
creature.setBankBalance(Long.parseLong(parameters.get('transaction.txtInputTo.Text')))
IntentFactory.sendSystemMessage(player, '@base_player:bank_success')
}
@@ -31,15 +31,20 @@ import com.projectswg.common.data.radial.RadialItem
import com.projectswg.common.data.radial.RadialOption
import com.projectswg.holocore.resources.objects.SWGObject
import com.projectswg.holocore.resources.player.Player
import com.projectswg.holocore.scripts.radial.RadialHandlerInterface
static def getOptions(List<RadialOption> options, Player player, SWGObject target) {
options.add(new RadialOption(RadialItem.ITEM_USE))
options.add(new RadialOption(RadialItem.EXAMINE))
}
static def handleSelection(Player player, SWGObject target, RadialItem selection) {
switch (selection) {
case RadialItem.ITEM_USE:
break
class TerminalBazaarRadial implements RadialHandlerInterface {
def getOptions(List<RadialOption> options, Player player, SWGObject target) {
options.add(new RadialOption(RadialItem.ITEM_USE))
options.add(new RadialOption(RadialItem.EXAMINE))
}
def handleSelection(Player player, SWGObject target, RadialItem selection) {
switch (selection) {
case RadialItem.ITEM_USE:
break
}
}
}
@@ -1,79 +0,0 @@
/***********************************************************************************
* Copyright (c) 2018 /// Project SWG /// www.projectswg.com *
* *
* ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on *
* July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. *
* Our goal is to create an emulator which will provide a server for players to *
* continue playing a game similar to the one they used to play. We are basing *
* it on the final publish of the game prior to end-game events. *
* *
* 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.scripts.radial.terminal
import com.projectswg.common.data.radial.RadialItem
import com.projectswg.common.data.radial.RadialOption
import com.projectswg.holocore.resources.objects.SWGObject
import com.projectswg.holocore.resources.player.Player
static def getOptions(String type, List<RadialOption> options, Player player, SWGObject target) {
switch (type) {
case "bank":
TerminalBankRadial.getOptions(options, player, target)
break
case "bazaar":
TerminalBazaarRadial.getOptions(options, player, target)
break
case "character_builder":
TerminalCharacterBuilderRadial.getOptions(options, player, target)
break
case "ticket":
TerminalTicketRadial.getOptions(options, player, target)
break
case "ticket_collector":
TerminalTicketCollectorRadial.getOptions(options, player, target)
break
case "travel":
TerminalTravelRadial.getOptions(options, player, target)
break
}
}
static def handleSelection(String type, Player player, SWGObject target, RadialItem selection) {
switch (type) {
case "bank":
TerminalBankRadial.handleSelection(player, target, selection)
break
case "bazaar":
TerminalBazaarRadial.handleSelection(player, target, selection)
break
case "character_builder":
TerminalCharacterBuilderRadial.handleSelection(player, target, selection)
break
case "ticket":
TerminalTicketRadial.handleSelection(player, target, selection)
break
case "ticket_collector":
TerminalTicketCollectorRadial.handleSelection(player, target, selection)
break
case "travel":
TerminalTravelRadial.handleSelection(player, target, selection)
break
}
}
@@ -32,16 +32,21 @@ import com.projectswg.common.data.radial.RadialOption
import com.projectswg.holocore.intents.travel.TicketUseIntent
import com.projectswg.holocore.resources.objects.SWGObject
import com.projectswg.holocore.resources.player.Player
import com.projectswg.holocore.scripts.radial.RadialHandlerInterface
static def getOptions(List<RadialOption> options, Player player, SWGObject target) {
options.add(new RadialOption(RadialItem.ITEM_USE))
options.add(new RadialOption(RadialItem.EXAMINE))
}
static def handleSelection(Player player, SWGObject target, RadialItem selection) {
switch (selection) {
case RadialItem.ITEM_USE:
new TicketUseIntent(player).broadcast()
break
class TerminalTicketCollectorRadial implements RadialHandlerInterface {
def getOptions(List<RadialOption> options, Player player, SWGObject target) {
options.add(new RadialOption(RadialItem.ITEM_USE))
options.add(new RadialOption(RadialItem.EXAMINE))
}
def handleSelection(Player player, SWGObject target, RadialItem selection) {
switch (selection) {
case RadialItem.ITEM_USE:
new TicketUseIntent(player).broadcast()
break
}
}
}
@@ -32,16 +32,21 @@ import com.projectswg.common.data.radial.RadialOption
import com.projectswg.holocore.intents.travel.TicketUseIntent
import com.projectswg.holocore.resources.objects.SWGObject
import com.projectswg.holocore.resources.player.Player
import com.projectswg.holocore.scripts.radial.RadialHandlerInterface
static def getOptions(List<RadialOption> options, Player player, SWGObject target) {
options.add(new RadialOption(RadialItem.ITEM_USE))
options.add(new RadialOption(RadialItem.EXAMINE))
}
static def handleSelection(Player player, SWGObject target, RadialItem selection) {
switch (selection) {
case RadialItem.ITEM_USE:
new TicketUseIntent(player, target).broadcast()
break
class TerminalTicketRadial implements RadialHandlerInterface {
def getOptions(List<RadialOption> options, Player player, SWGObject target) {
options.add(new RadialOption(RadialItem.ITEM_USE))
options.add(new RadialOption(RadialItem.EXAMINE))
}
def handleSelection(Player player, SWGObject target, RadialItem selection) {
switch (selection) {
case RadialItem.ITEM_USE:
new TicketUseIntent(player, target).broadcast()
break
}
}
}
@@ -32,16 +32,21 @@ import com.projectswg.common.data.radial.RadialOption
import com.projectswg.holocore.intents.travel.TravelPointSelectionIntent
import com.projectswg.holocore.resources.objects.SWGObject
import com.projectswg.holocore.resources.player.Player
import com.projectswg.holocore.scripts.radial.RadialHandlerInterface
static def getOptions(List<RadialOption> options, Player player, SWGObject target) {
options.add(new RadialOption(RadialItem.ITEM_USE))
options.add(new RadialOption(RadialItem.EXAMINE))
}
static def handleSelection(Player player, SWGObject target, RadialItem selection) {
switch (selection) {
case RadialItem.ITEM_USE:
new TravelPointSelectionIntent(player.getCreatureObject(), false).broadcast()
break
class TerminalTravelRadial implements RadialHandlerInterface {
def getOptions(List<RadialOption> options, Player player, SWGObject target) {
options.add(new RadialOption(RadialItem.ITEM_USE))
options.add(new RadialOption(RadialItem.EXAMINE))
}
def handleSelection(Player player, SWGObject target, RadialItem selection) {
switch (selection) {
case RadialItem.ITEM_USE:
new TravelPointSelectionIntent(player.getCreatureObject(), false).broadcast()
break
}
}
}
@@ -24,36 +24,23 @@
* 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.intents.radial;
package com.projectswg.holocore.intents.combat.loot;
import com.projectswg.common.control.Intent;
import com.projectswg.common.data.radial.RadialItem;
import com.projectswg.holocore.resources.objects.SWGObject;
import com.projectswg.holocore.resources.player.Player;
public class RadialSelectionIntent extends Intent {
public class LootRequestIntent extends Intent {
private Player player;
private SWGObject target;
private RadialItem selection;
private final Player player;
private final SWGObject target;
private final LootType type;
public RadialSelectionIntent(Player player, SWGObject target, RadialItem selection) {
setPlayer(player);
setTarget(target);
setSelection(selection);
}
public void setPlayer(Player player) {
public LootRequestIntent(Player player, SWGObject target, LootType type) {
this.player = player;
}
public void setTarget(SWGObject target) {
this.target = target;
}
public void setSelection(RadialItem selection) {
this.selection = selection;
this.type = type;
}
public Player getPlayer() {
@@ -64,8 +51,18 @@ public class RadialSelectionIntent extends Intent {
return target;
}
public RadialItem getSelection() {
return selection;
public LootType getType() {
return type;
}
public static void broadcast(Player player, SWGObject target, LootType type) {
new LootRequestIntent(player, target, type).broadcast();
}
public enum LootType {
LOOT,
LOOT_ALL,
CREDITS
}
}
@@ -42,4 +42,8 @@ public class DestroyObjectIntent extends Intent {
return obj;
}
public static void broadcast(SWGObject obj) {
new DestroyObjectIntent(obj).broadcast();
}
}
@@ -24,48 +24,25 @@
* 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.intents.radial;
package com.projectswg.holocore.intents.player.uniform;
import com.projectswg.common.control.Intent;
import com.projectswg.common.network.packets.swg.zone.object_controller.ObjectMenuRequest;
import com.projectswg.holocore.resources.objects.SWGObject;
import com.projectswg.holocore.resources.player.Player;
public class RadialRequestIntent extends Intent {
public class OpenUniformBoxIntent extends Intent {
private Player player;
private SWGObject target;
private ObjectMenuRequest request;
private final Player player;
public RadialRequestIntent(Player player, SWGObject target, ObjectMenuRequest request) {
setPlayer(player);
setTarget(target);
setRequest(request);
}
public void setPlayer(Player player) {
public OpenUniformBoxIntent(Player player) {
this.player = player;
}
public void setTarget(SWGObject target) {
this.target = target;
}
public void setRequest(ObjectMenuRequest request) {
this.request = request;
}
public Player getPlayer() {
return player;
}
public SWGObject getTarget() {
return target;
public static void broadcast(Player player) {
new OpenUniformBoxIntent(player).broadcast();
}
public ObjectMenuRequest getRequest() {
return request;
}
}
@@ -1,83 +0,0 @@
/***********************************************************************************
* Copyright (c) 2018 /// Project SWG /// www.projectswg.com *
* *
* ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on *
* July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. *
* Our goal is to create an emulator which will provide a server for players to *
* continue playing a game similar to the one they used to play. We are basing *
* it on the final publish of the game prior to end-game events. *
* *
* 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.intents.radial;
import java.util.List;
import com.projectswg.common.control.Intent;
import com.projectswg.common.data.radial.RadialOption;
import com.projectswg.holocore.resources.objects.SWGObject;
import com.projectswg.holocore.resources.player.Player;
public class RadialResponseIntent extends Intent {
private Player player;
private SWGObject target;
private List<RadialOption> options;
private int counter;
public RadialResponseIntent(Player player, SWGObject target, List<RadialOption> options, int counter) {
setPlayer(player);
setTarget(target);
setOptions(options);
setCounter(counter);
}
public void setPlayer(Player player) {
this.player = player;
}
public void setTarget(SWGObject target) {
this.target = target;
}
public void setOptions(List<RadialOption> options) {
this.options = options;
}
public void setCounter(int counter) {
this.counter = counter;
}
public Player getPlayer() {
return player;
}
public SWGObject getTarget() {
return target;
}
public List<RadialOption> getOptions() {
return options;
}
public int getCounter() {
return counter;
}
}
@@ -26,25 +26,24 @@
***********************************************************************************/
package com.projectswg.holocore.resources.collections;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.AbstractList;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicInteger;
import com.projectswg.common.concurrency.SynchronizedList;
import com.projectswg.common.debug.Assert;
import com.projectswg.common.debug.Log;
import com.projectswg.common.encoding.Encodable;
import com.projectswg.common.encoding.Encoder;
import com.projectswg.common.encoding.StringType;
import com.projectswg.common.network.NetBuffer;
import com.projectswg.common.network.packets.swg.zone.baselines.Baseline.BaselineType;
import com.projectswg.holocore.resources.objects.SWGObject;
import java.lang.reflect.InvocationTargetException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.AbstractList;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicInteger;
/**
* Supports a list of elements which automatically sends data as a delta when changed for baselines.
*
@@ -70,8 +69,6 @@ public class SWGList<E> extends CopyOnWriteArrayList<E> implements Encodable {
* that this is an extension of {@link AbstractList} and makes use of
* {@link java.util.ArrayList}
*
* @param baseline {@link BaselineType} for this list, should be the same as the parent class
* this list resides in
* @param view The baseline number this list resides in
* @param updateType The update variable used for sending a delta, it's the operand count that
* this list resides at within the baseline
@@ -84,9 +81,8 @@ public class SWGList<E> extends CopyOnWriteArrayList<E> implements Encodable {
* Creates a new {@link SWGList} with the given StringType to encode in. Note that this
* constructor must be used if the elements within the list is a String.
*
* @param baseline {@link BaselineType} for this list, should be the same as the parent class
* this list resides in
* @param view The baseline number this list resides in
* @param updateType The update number for this variable
* @param strType The {@link StringType} of the string, required only if the element in the list
* is a String as it's used for encoding either Unicode or ASCII characters
*/
@@ -217,12 +213,12 @@ public class SWGList<E> extends CopyOnWriteArrayList<E> implements Encodable {
private boolean decodeElement(NetBuffer wrap, Class<E> elementType, boolean encodable) {
if (encodable) {
try {
E instance = elementType.newInstance();
E instance = elementType.getConstructor().newInstance();
if (instance instanceof Encodable) {
((Encodable) instance).decode(wrap);
add(instance);
}
} catch (InstantiationException | IllegalAccessException e) {
} catch (NoSuchMethodException | InvocationTargetException | InstantiationException | IllegalAccessException e) {
Log.e(e);
return false;
}
@@ -299,7 +295,7 @@ public class SWGList<E> extends CopyOnWriteArrayList<E> implements Encodable {
private void addObjectData(int index, E obj, byte update) {
byte[] encodedData = Encoder.encode(obj, strType);
Assert.notNull(encodedData);
Objects.requireNonNull(encodedData, "Unable to encode obj");
synchronized (data) {
dataSize += encodedData.length;
@@ -26,16 +26,6 @@
***********************************************************************************/
package com.projectswg.holocore.resources.collections;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.AbstractSet;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.atomic.AtomicInteger;
import com.projectswg.common.concurrency.SynchronizedList;
import com.projectswg.common.concurrency.SynchronizedSet;
import com.projectswg.common.debug.Log;
@@ -43,10 +33,15 @@ import com.projectswg.common.encoding.Encodable;
import com.projectswg.common.encoding.Encoder;
import com.projectswg.common.encoding.StringType;
import com.projectswg.common.network.NetBuffer;
import com.projectswg.common.network.packets.swg.zone.baselines.Baseline;
import com.projectswg.holocore.resources.objects.SWGObject;
import java.lang.reflect.InvocationTargetException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.*;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.atomic.AtomicInteger;
public class SWGSet<E> extends CopyOnWriteArraySet<E> implements Encodable {
private static final long serialVersionUID = 1L;
@@ -65,8 +60,6 @@ public class SWGSet<E> extends CopyOnWriteArraySet<E> implements Encodable {
* Creates a new {@link SWGSet} for the defined baseline with the given view and update. Note
* that this is an extension of {@link AbstractSet} and makes use of {@link HashSet}
*
* @param baseline {@link Baseline.BaselineType} for this set, should be the same as the parent
* class this list resides in
* @param view The baseline number this list resides in
* @param updateType The update variable used for sending a delta, it's the operand count that
* this list resides at within the baseline
@@ -79,9 +72,8 @@ public class SWGSet<E> extends CopyOnWriteArraySet<E> implements Encodable {
* Creates a new {@link SWGSet} with the given StringType to encode in. Note that this
* constructor must be used if the elements within the list is a String.
*
* @param baseline {@link Baseline.BaselineType} for this set, should be the same as the parent
* class this list resides in
* @param view The baseline number this set resides in
* @param updateType The update number for this variable
* @param strType The {@link StringType} of the string, required only if the element in the set
* is a String as it's used for encoding either Unicode or ASCII characters
*/
@@ -269,12 +261,12 @@ public class SWGSet<E> extends CopyOnWriteArraySet<E> implements Encodable {
private boolean decodeElement(NetBuffer wrap, Class<E> elementType, boolean encodable) {
if (encodable) {
try {
E instance = elementType.newInstance();
E instance = elementType.getConstructor().newInstance();
if (instance instanceof Encodable) {
((Encodable) instance).decode(wrap);
add(instance);
}
} catch (InstantiationException | IllegalAccessException e) {
} catch (NoSuchMethodException | InvocationTargetException | InstantiationException | IllegalAccessException e) {
Log.e(e);
return false;
}
@@ -27,190 +27,56 @@
package com.projectswg.holocore.services.collections;
import com.projectswg.common.control.Service;
import com.projectswg.common.data.info.RelationalServerData;
import com.projectswg.common.data.info.RelationalServerFactory;
import com.projectswg.common.data.radial.RadialOption;
import com.projectswg.common.debug.Log;
import com.projectswg.holocore.ProjectSWG;
import com.projectswg.holocore.intents.GrantClickyCollectionIntent;
import com.projectswg.holocore.intents.radial.RadialRequestIntent;
import com.projectswg.holocore.intents.radial.RadialResponseIntent;
import com.projectswg.holocore.intents.radial.RadialSelectionIntent;
import com.projectswg.holocore.resources.objects.collections.ClickyCollectionItem;
import com.projectswg.holocore.resources.objects.collections.CollectionItem;
import com.projectswg.holocore.resources.server_info.SdbLoader;
import com.projectswg.holocore.resources.server_info.SdbLoader.SdbResultSet;
import com.projectswg.holocore.resources.server_info.StandardLog;
import com.projectswg.holocore.scripts.radial.RadialHandler;
import com.projectswg.holocore.scripts.radial.collection.WorldItemRadial;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.io.File;
import java.io.IOException;
public class CollectionService extends Service {
private static final String GET_CLICKY_COLLECTION_ITEMS_SQL = "SELECT iff_template FROM collection_clicky";
private static final String GET_CONSUME_COLLECTION_ITEMS_SQL = "SELECT item_name, iff_template FROM collection";
private static final String GET_CLICKY_DETAILS_SQL = "SELECT * FROM collection_clicky WHERE iff_template=?";
private static final String GET_CONSUME_DETAILS_SQL = "SELECT * FROM collection WHERE iff_template=?";
private RelationalServerData clickyDatabase;
private RelationalServerData consumeDatabase;
private final PreparedStatement getClickyCollectionItemsStatement;
private final PreparedStatement getConsumeCollectionItemsStatement;
private final List<String> clickyCollectionItems = new ArrayList<>();
private final List<ConsumeCollection> consumeCollectionItems = new ArrayList<>();
public CollectionService() {
clickyDatabase = RelationalServerFactory.getServerData("collections/collection_clicky.db", "collection_clicky");
consumeDatabase = RelationalServerFactory.getServerData("items/collection.db", "collection");
if (clickyDatabase == null)
throw new ProjectSWG.CoreException("Database collection_clicky failed to load");
if (consumeDatabase == null)
throw new ProjectSWG.CoreException("Database collection failed to load");
getClickyCollectionItemsStatement = clickyDatabase.prepareStatement(GET_CLICKY_DETAILS_SQL);
getConsumeCollectionItemsStatement = consumeDatabase.prepareStatement(GET_CONSUME_DETAILS_SQL);
registerClickyCollectionItems();
registerConsumeCollectionItems();
registerForIntent(RadialRequestIntent.class, this::handleRadialRequestIntent);
registerForIntent(RadialSelectionIntent.class, this::handleRadialSelectionIntent);
}
private void handleRadialRequestIntent(RadialRequestIntent rri){
String iff = rri.getTarget().getTemplate();
String itemName = rri.getTarget().getStringId().getKey();
if (isClickyCollectionItem(iff) || isConsumeCollectionItem(itemName, iff)) {
List<RadialOption> options = new ArrayList<>(rri.getRequest().getOptions());
WorldItemRadial.getOptions(options, rri.getPlayer(), rri.getTarget());
new RadialResponseIntent(rri.getPlayer(), rri.getTarget(), options, rri.getRequest().getCounter()).broadcast();
}
}
private void handleRadialSelectionIntent(RadialSelectionIntent rsi){
String iff = rsi.getTarget().getTemplate();
String itemName = rsi.getTarget().getStringId().getKey();
boolean isClicky = isClickyCollectionItem(iff);
if (isClicky || isConsumeCollectionItem(itemName, iff)) {
new GrantClickyCollectionIntent(rsi.getPlayer().getCreatureObject(), rsi.getTarget(), getCollectionDetails(iff, isClicky)).broadcast();
}
}
private void registerClickyCollectionItems() {
try (ResultSet set = clickyDatabase.executeQuery(GET_CLICKY_COLLECTION_ITEMS_SQL)) {
while (set.next()) {
String iff = set.getString("iff_template");
if (!clickyCollectionItems.contains(iff)) {
clickyCollectionItems.add(iff);
}
}
} catch (SQLException ex) {
Log.e(ex);
}
//clickyDatabase.close();
}
private void registerConsumeCollectionItems() {
try (ResultSet set = consumeDatabase.executeQuery(GET_CONSUME_COLLECTION_ITEMS_SQL)) {
while (set.next()) {
ConsumeCollection collection = new ConsumeCollection(set.getString("item_name"), set.getString("iff_template"));
if (!consumeCollectionItems.contains(collection)) {
consumeCollectionItems.add(collection);
}
}
} catch (SQLException ex) {
Log.e(ex);
}
//consumeDatabase.close();
}
private CollectionItem getCollectionDetails(String iff, boolean isClicky) {
if (isClicky)
return getClickyCollectionDetails(iff);
else
return getCollectionDetails(iff);
}
private CollectionItem getCollectionDetails(String iff) {
String cleanedIff = cleanIff(iff);
CollectionItem collection = null;
try {
synchronized (getConsumeCollectionItemsStatement) {
getConsumeCollectionItemsStatement.setString(1, cleanedIff);
ResultSet set = getConsumeCollectionItemsStatement.executeQuery();
while (set.next()) {
collection = new CollectionItem(set.getString("collection_slot_name"), set.getString("collection_name"), set.getString("iff_template"));
}
}
} catch (SQLException e) {
Log.e(e);
}
return collection;
}
private ClickyCollectionItem getClickyCollectionDetails(String iff) {
String cleanedIff = cleanIff(iff);
ClickyCollectionItem collection = null;
try {
ResultSet set;
synchronized (getClickyCollectionItemsStatement) {
getClickyCollectionItemsStatement.setString(1, cleanedIff);
set = getClickyCollectionItemsStatement.executeQuery();
}
}
@Override
public boolean initialize() {
int count = 0;
long startTime = StandardLog.onStartLoad("collections");
try (SdbResultSet set = SdbLoader.load(new File("serverdata/items/collection.sdb"))) {
while (set.next()) {
collection = new ClickyCollectionItem(set.getString("slotName"), set.getString("collectionName"), set.getInt("object_id"), set.getString("iff_template"), set.getString("terrain"), set.getDouble("x"), set.getDouble("y"));
String iff = set.getText("iff_template");
String slotName = set.getText("collection_slot_name");
String collectionName = set.getText("collection_name");
RadialHandler.registerHandler(iff, new WorldItemRadial(new CollectionItem(slotName, collectionName, iff)));
count++;
}
} catch (SQLException e) {
} catch (IOException e) {
Log.e(e);
}
return collection;
}
private boolean isClickyCollectionItem(String iff) {
return clickyCollectionItems.contains(cleanIff(iff));
}
private boolean isConsumeCollectionItem(String itemName, String iffTemplate) {
ConsumeCollection collection = new ConsumeCollection(itemName, iffTemplate);
return isConsumeCollectionItem(collection);
}
private boolean isConsumeCollectionItem(ConsumeCollection collection) {
return consumeCollectionItems.contains(collection);
}
private static String cleanIff(String iff) {
return iff.replace("shared_", "");
}
private class ConsumeCollection {
private String itemName;
private String iffTemplate;
public ConsumeCollection(String itemName, String iffTemplate) {
this.itemName = itemName;
this.iffTemplate = iffTemplate;
}
@Override
public boolean equals(Object o) {
if (!(o instanceof ConsumeCollection))
return false;
String myTemplate = cleanIff(iffTemplate);
String oTemplate = cleanIff(((ConsumeCollection) o).iffTemplate);
return itemName.equals(((ConsumeCollection) o).itemName) && myTemplate.equals(oTemplate);
try (SdbResultSet set = SdbLoader.load(new File("serverdata/collections/collection_clicky.sdb"))) {
while (set.next()) {
String iff = set.getText("iff_template");
String slotName = set.getText("slotName");
String collectionName = set.getText("collectionName");
int objectId = (int) set.getInt("object_id");
String terrain = set.getText("terrain");
double x = set.getReal("x");
double y = set.getReal("y");
RadialHandler.registerHandler(iff, new WorldItemRadial(new ClickyCollectionItem(slotName, collectionName, objectId, iff, terrain, x, y)));
count++;
}
} catch (IOException e) {
Log.e(e);
}
StandardLog.onEndLoad(count, "collections", startTime);
return super.initialize();
}
}
@@ -56,12 +56,11 @@ import com.projectswg.holocore.intents.chat.SystemMessageIntent;
import com.projectswg.holocore.intents.combat.CorpseLootedIntent;
import com.projectswg.holocore.intents.combat.CreatureKilledIntent;
import com.projectswg.holocore.intents.combat.LootItemIntent;
import com.projectswg.holocore.intents.combat.loot.LootRequestIntent;
import com.projectswg.holocore.intents.object.ContainerTransferIntent;
import com.projectswg.holocore.intents.object.CreateStaticItemIntent;
import com.projectswg.holocore.intents.object.DestroyObjectIntent;
import com.projectswg.holocore.intents.object.ObjectCreatedIntent;
import com.projectswg.holocore.intents.radial.RadialRequestIntent;
import com.projectswg.holocore.intents.radial.RadialResponseIntent;
import com.projectswg.holocore.intents.radial.RadialSelectionIntent;
import com.projectswg.holocore.resources.config.ConfigFile;
import com.projectswg.holocore.resources.containers.ContainerPermissionsType;
import com.projectswg.holocore.resources.objects.SWGObject;
@@ -98,8 +97,7 @@ public final class LootService extends Service {
registerForIntent(ChatCommandIntent.class, this::handleChatCommand);
registerForIntent(ContainerTransferIntent.class, this::handleContainerTransfer);
registerForIntent(CreatureKilledIntent.class, this::handleCreatureKilled);
registerForIntent(RadialSelectionIntent.class, this::handleRadialSelection);
registerForIntent(RadialRequestIntent.class, this::handleRadialRequestIntent);
registerForIntent(LootRequestIntent.class, this::handleLootRequestIntent);
registerForIntent(LootItemIntent.class, this::handleLootItemIntent);
}
@@ -289,77 +287,28 @@ public final class LootService extends Service {
lootAll(cci.getSource(), cci.getTarget());
}
private void handleRadialSelection(RadialSelectionIntent rsi) {
Player player = rsi.getPlayer();
CreatureObject looter = player.getCreatureObject();
SWGObject object = rsi.getTarget();
switch (rsi.getSelection()) {
case LOOT: {
if (!getLootPermission(looter, object))
return;
lootBox(player, object);
break;
}
case LOOT_ALL: {
if (!getLootPermission(looter, object))
return;
lootAll(looter, object);
break;
}
case TRANSFER_CREDITS_TO_BANK_ACCOUNT: {
SWGObject container = object.getParent();
SWGObject owner = container.getParent();
if (!getLootPermission(looter, owner))
return;
long cash = ((CreditObject) object).getAmount();
looter.addToBank(cash);
new SystemMessageIntent(player, new ProsePackage("StringId", new StringId("base_player", "prose_transfer_success"), "DI", (int) cash)).broadcast();
object.moveToContainer(null);
if (owner instanceof CreatureObject && container.getContainedObjects().isEmpty()) {
CreatureObject corpse = (CreatureObject) owner;
new CorpseLootedIntent(corpse).broadcast();
player.sendPacket(new StopClientEffectObjectByLabelMessage(corpse.getObjectId(), "lootMe", false));
}
break;
}
default:
break;
}
}
private void handleRadialRequestIntent(RadialRequestIntent rri){
SWGObject target = rri.getTarget();
private void handleLootRequestIntent(LootRequestIntent lri) {
Player player = lri.getPlayer();
CreatureObject looter = player.getCreatureObject();
SWGObject target = lri.getTarget();
if (target instanceof AIObject) {
CreatureObject creature = (CreatureObject) target;
if (creature.getHealth() > 0) {
// Live creatures shouldn't get a loot radial
return;
}
// TODO permissions check
List<RadialOption> options = new ArrayList<>(rri.getRequest().getOptions());
RadialOption loot = new RadialOption(RadialItem.LOOT);
loot.addChild(RadialItem.LOOT_ALL);
options.add(loot);
new RadialResponseIntent(rri.getPlayer(), target, options, rri.getRequest().getCounter()).broadcast();
} else if (target instanceof CreditObject) {
List<RadialOption> options = new ArrayList<>(rri.getRequest().getOptions());
RadialOption transfer = new RadialOption(RadialItem.TRANSFER_CREDITS_TO_BANK_ACCOUNT);
options.add(transfer);
new RadialResponseIntent(rri.getPlayer(), target, options, rri.getRequest().getCounter()).broadcast();
switch (lri.getType()) {
case LOOT:
if (!getLootPermission(looter, target))
return;
lootBox(player, target);
break;
case LOOT_ALL:
if (!getLootPermission(looter, target))
return;
lootAll(looter, target);
break;
case CREDITS:
lootCredits(player, looter, target);
break;
}
}
@@ -435,6 +384,26 @@ public final class LootService extends Service {
loot.forEach(item -> loot((CreatureObject) looter, item, lootInventory));
}
private void lootCredits(Player player, CreatureObject looter, SWGObject target) {
SWGObject container = target.getParent();
SWGObject owner = container.getParent();
if (!getLootPermission(looter, owner))
return;
long cash = ((CreditObject) target).getAmount();
looter.addToBank(cash);
DestroyObjectIntent.broadcast(target);
new SystemMessageIntent(player, new ProsePackage("StringId", new StringId("base_player", "prose_transfer_success"), "DI", (int) cash)).broadcast();
if (owner instanceof CreatureObject && container.getContainedObjects().isEmpty()) {
CreatureObject corpse = (CreatureObject) owner;
new CorpseLootedIntent(corpse).broadcast();
player.sendPacket(new StopClientEffectObjectByLabelMessage(corpse.getObjectId(), "lootMe", false));
}
}
private void randomGroupLoot(GroupObject lootGroup, SWGObject corpse) {
if (!(corpse instanceof AIObject)) {
return;
@@ -37,7 +37,6 @@ import com.projectswg.holocore.services.commands.EntertainmentService;
import com.projectswg.holocore.services.crafting.CraftingManager;
import com.projectswg.holocore.services.experience.ExperienceManager;
import com.projectswg.holocore.services.faction.FactionService;
import com.projectswg.holocore.services.galaxy.terminals.TerminalService;
import com.projectswg.holocore.services.group.GroupService;
import com.projectswg.holocore.services.sui.SuiService;
@@ -50,7 +49,6 @@ public class GameManager extends Manager {
addChildService(new CollectionService());
addChildService(new CollectionBadgeManager());
addChildService(new EnvironmentService());
addChildService(new TerminalService());
addChildService(new FactionService());
addChildService(new GroupService());
addChildService(new SkillModService());
@@ -0,0 +1,38 @@
/***********************************************************************************
* Copyright (c) 2018 /// Project SWG /// www.projectswg.com *
* *
* ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on *
* July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. *
* Our goal is to create an emulator which will provide a server for players to *
* continue playing a game similar to the one they used to play. We are basing *
* it on the final publish of the game prior to end-game events. *
* *
* 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.galaxy;
import com.projectswg.common.control.Service;
public class TerminalService extends Service {
public TerminalService() {
}
}
@@ -1,104 +0,0 @@
/***********************************************************************************
* Copyright (c) 2018 /// Project SWG /// www.projectswg.com *
* *
* ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on *
* July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. *
* Our goal is to create an emulator which will provide a server for players to *
* continue playing a game similar to the one they used to play. We are basing *
* it on the final publish of the game prior to end-game events. *
* *
* 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.galaxy.terminals;
import com.projectswg.common.control.Service;
import com.projectswg.common.data.radial.RadialOption;
import com.projectswg.common.debug.Log;
import com.projectswg.holocore.intents.radial.RadialRequestIntent;
import com.projectswg.holocore.intents.radial.RadialResponseIntent;
import com.projectswg.holocore.intents.radial.RadialSelectionIntent;
import com.projectswg.holocore.resources.server_info.SdbLoader;
import com.projectswg.holocore.resources.server_info.SdbLoader.SdbResultSet;
import com.projectswg.holocore.scripts.radial.terminal.TerminalRadial;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class TerminalService extends Service {
private static final String GET_ALL_TEMPLATES_SQL = "SELECT iff FROM radials";
private static final String GET_SCRIPT_FOR_IFF_SQL = "SELECT script FROM radials WHERE iff = ?";
private final Set<String> templates;
public TerminalService() {
templates = new HashSet<>();
registerForIntent(RadialRequestIntent.class, this::handleRadialRequestIntent);
registerForIntent(RadialSelectionIntent.class, this::handleRadialSelectionIntent);
}
@Override
public boolean initialize() {
try (SdbResultSet set = SdbLoader.load(new File("serverdata/radial/radials.sdb"))) {
templates.clear();
while (set.next()) {
templates.add(set.getText("iff"));
}
} catch (IOException e) {
Log.e(e);
}
return super.initialize();
}
private void handleRadialRequestIntent(RadialRequestIntent rri){
String script = lookupScript(rri.getTarget().getTemplate());
if (script == null)
return;
List<RadialOption> options = new ArrayList<>(rri.getRequest().getOptions());
TerminalRadial.getOptions(script, options, rri.getPlayer(), rri.getTarget());
new RadialResponseIntent(rri.getPlayer(), rri.getTarget(), options, rri.getRequest().getCounter()).broadcast();
}
private void handleRadialSelectionIntent(RadialSelectionIntent rsi){
String script = lookupScript(rsi.getTarget().getTemplate());
if (script == null)
return;
TerminalRadial.handleSelection(script, rsi.getPlayer(), rsi.getTarget(), rsi.getSelection());
}
private String lookupScript(String iff) {
if (!templates.contains(iff))
return null;
try (SdbResultSet set = SdbLoader.load(new File("serverdata/radial/radials.sdb"))) {
while (set.next()) {
if (set.getText("iff").equals(iff)) {
return set.getText("script");
}
}
} catch (IOException e) {
Log.e(e);
}
return null;
}
}
@@ -26,8 +26,6 @@
***********************************************************************************/
package com.projectswg.holocore.services.objects;
import java.util.List;
import com.projectswg.common.control.Service;
import com.projectswg.common.data.radial.RadialItem;
import com.projectswg.common.data.radial.RadialOption;
@@ -36,25 +34,29 @@ import com.projectswg.common.network.packets.SWGPacket;
import com.projectswg.common.network.packets.swg.zone.ObjectMenuSelect;
import com.projectswg.common.network.packets.swg.zone.object_controller.ObjectMenuRequest;
import com.projectswg.common.network.packets.swg.zone.object_controller.ObjectMenuResponse;
import com.projectswg.holocore.intents.network.GalacticPacketIntent;
import com.projectswg.holocore.intents.radial.RadialRequestIntent;
import com.projectswg.holocore.intents.radial.RadialResponseIntent;
import com.projectswg.holocore.intents.radial.RadialSelectionIntent;
import com.projectswg.holocore.resources.objects.SWGObject;
import com.projectswg.holocore.resources.objects.creature.CreatureObject;
import com.projectswg.holocore.resources.player.Player;
import com.projectswg.holocore.scripts.radial.RadialHandler;
import com.projectswg.holocore.services.galaxy.GalacticManager;
import java.util.ArrayList;
import java.util.List;
public class RadialService extends Service {
public RadialService() {
registerForIntent(GalacticPacketIntent.class, RadialService::handleGalacticPacketIntent);
registerForIntent(RadialResponseIntent.class, RadialService::handleRadialResponseIntent);
// RadialRegisterIntent
registerForIntent(GalacticPacketIntent.class, this::handleGalacticPacketIntent);
}
private static void handleGalacticPacketIntent(GalacticPacketIntent gpi){
@Override
public boolean initialize() {
RadialHandler.initialize();
return super.initialize();
}
private void handleGalacticPacketIntent(GalacticPacketIntent gpi) {
SWGPacket p = gpi.getPacket();
if (p instanceof ObjectMenuRequest) {
onRequest(gpi.getObjectManager(), (ObjectMenuRequest) p);
@@ -63,7 +65,7 @@ public class RadialService extends Service {
}
}
private static void onRequest(ObjectManager objectManager, ObjectMenuRequest request) {
private void onRequest(ObjectManager objectManager, ObjectMenuRequest request) {
SWGObject requestor = objectManager.getObjectById(request.getRequestorId());
SWGObject target = objectManager.getObjectById(request.getTargetId());
if (target == null)
@@ -77,16 +79,13 @@ public class RadialService extends Service {
Log.w("Requestor of target: %s does not have an owner! %s", target, requestor);
return;
}
new RadialRequestIntent(player, target, request).broadcast();
List<RadialOption> options = new ArrayList<>();
RadialHandler.getOptions(options, player, target);
sendResponse(player, target, options, request.getCounter());
}
private static void handleRadialResponseIntent(RadialResponseIntent rri) {
Player player = rri.getPlayer();
sendResponse(player, rri.getTarget(), rri.getOptions(), rri.getCounter());
}
private static void onSelection(GalacticManager galacticManager, Player player, ObjectMenuSelect select) {
private void onSelection(GalacticManager galacticManager, Player player, ObjectMenuSelect select) {
SWGObject target = galacticManager.getObjectManager().getObjectById(select.getObjectId());
if (target == null) {
Log.e("Selection target [%d] does not exist!", select.getObjectId());
@@ -96,14 +95,16 @@ public class RadialService extends Service {
Log.e("Selection requestor does not exist! Target: [%d] %s", target.getObjectId(), target.getTemplate());
return;
}
RadialItem selection = RadialItem.getFromId(select.getSelection());
if (selection == null) {
Log.e("RadialItem does not exist with selection id: %d", select.getSelection());
return;
}
new RadialSelectionIntent(player, target, selection).broadcast();
RadialHandler.handleSelection(player, target, selection);
}
private static void sendResponse(Player player, SWGObject target, List<RadialOption> options, int counter) {
ObjectMenuResponse menuResponse = new ObjectMenuResponse(player.getCreatureObject().getObjectId());
menuResponse.setTargetId(target.getObjectId());
@@ -112,5 +113,5 @@ public class RadialService extends Service {
menuResponse.setCounter(counter);
player.sendPacket(menuResponse);
}
}
@@ -41,7 +41,7 @@ import com.projectswg.common.debug.Log;
import com.projectswg.holocore.ProjectSWG;
import com.projectswg.holocore.intents.object.CreateStaticItemIntent;
import com.projectswg.holocore.intents.object.DestroyObjectIntent;
import com.projectswg.holocore.intents.radial.RadialSelectionIntent;
import com.projectswg.holocore.intents.player.uniform.OpenUniformBoxIntent;
import com.projectswg.holocore.resources.containers.ContainerPermissionsType;
import com.projectswg.holocore.resources.objects.SWGObject;
import com.projectswg.holocore.resources.objects.creature.CreatureObject;
@@ -63,7 +63,7 @@ public class UniformBoxService extends Service {
getUniformBoxStatement = uniformBoxDatabase.prepareStatement(GET_UNIFORMBOX_SQL);
registerForIntent(RadialSelectionIntent.class, this::handleRadialSelectionIntent);
registerForIntent(OpenUniformBoxIntent.class, this::handleOpenUniformBoxIntent);
}
@Override
@@ -72,20 +72,12 @@ public class UniformBoxService extends Service {
return super.terminate();
}
private void handleRadialSelectionIntent(RadialSelectionIntent rsi) {
if (!rsi.getTarget().getTemplate().equals(UNIFORM_BOX_IFF))
return;
if(!rsi.getSelection().equals(RadialItem.ITEM_USE)) {
return;
}
Player player = rsi.getPlayer();
private void handleOpenUniformBoxIntent(OpenUniformBoxIntent oubi) {
Player player = oubi.getPlayer();
CreatureObject creature = player.getCreatureObject();
SWGObject inventory = creature.getSlottedObject("inventory");
String profession = creature.getPlayerObject().getProfession();
new DestroyObjectIntent(rsi.getTarget()).broadcast();
handleCreateItems(inventory, profession, creature);
}
@@ -58,6 +58,7 @@ import com.projectswg.holocore.resources.player.Player.PlayerServer;
import com.projectswg.holocore.resources.player.PlayerState;
import com.projectswg.holocore.resources.server_info.DataManager;
import com.projectswg.holocore.services.CoreManager;
import com.projectswg.holocore.services.objects.ObjectManager.ObjectLookup;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
@@ -94,6 +95,30 @@ public class LoginService extends Service {
return super.initialize();
}
@Override
public boolean start() {
synchronized (deleteCharacter) {
try (ResultSet set = database.executeQuery("SELECT id FROM players")) {
while (set.next()) {
long id = set.getLong(1);
if (ObjectLookup.getObjectById(id) != null)
continue;
try {
deleteCharacter.setLong(1, id);
deleteCharacter.executeUpdate();
Log.d("Deleted character with id: %d", id);
} catch (SQLException e) {
Log.e(e);
}
}
} catch (SQLException e) {
Log.e(e);
}
}
return super.start();
}
@Override
public boolean terminate() {
database.close();