Skip to content
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

Holocore-598 Special attacks should say "Too tired" when their costs … #673

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pswgcommon
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/***********************************************************************************
* 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 PSWGCommon. *
* *
* --------------------------------------------------------------------------------*
* *
* PSWGCommon 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. *
* *
* PSWGCommon 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 PSWGCommon. If not, see <http://www.gnu.org/licenses/>. *
***********************************************************************************/
package com.projectswg.holocore.resources.gameplay.combat;

public enum CombatStatus {
UNKNOWN,
INVALID_TARGET,
NO_WEAPON,
NO_TARGET,
TOO_FAR,
SUCCESS,
TOO_TIRED,
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ object SWGColor {
val seagreen = RGB(46, 139, 87)
val lawngreen = RGB(124, 252, 0)
}

object Oranges {
val orange = RGB(255, 165, 0)
}

object Reds {
val orangered = RGB(255, 69, 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import com.projectswg.holocore.intents.gameplay.combat.KnockdownIntent;
import com.projectswg.holocore.intents.gameplay.combat.RequestCreatureDeathIntent;
import com.projectswg.holocore.intents.support.global.chat.SystemMessageIntent;
import com.projectswg.holocore.resources.gameplay.combat.CombatStatus;
import com.projectswg.holocore.resources.support.color.SWGColor;
import com.projectswg.holocore.resources.support.global.commands.CombatCommand;
import com.projectswg.holocore.resources.support.global.commands.Locomotion;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

package com.projectswg.holocore.services.gameplay.combat.command;

import com.projectswg.common.data.combat.CombatStatus;
import com.projectswg.holocore.resources.gameplay.combat.CombatStatus;
import com.projectswg.common.data.combat.HitLocation;
import com.projectswg.common.data.combat.TrailLocation;
import com.projectswg.common.data.encodables.tangible.PvpStatus;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@
import com.projectswg.common.data.RGB;
import com.projectswg.common.data.combat.AttackInfo;
import com.projectswg.common.data.combat.CombatSpamType;
import com.projectswg.common.data.combat.CombatStatus;
import com.projectswg.holocore.resources.gameplay.combat.CombatStatus;
import com.projectswg.common.data.combat.TrailLocation;
import com.projectswg.common.data.encodables.oob.StringId;
import com.projectswg.common.network.packets.swg.zone.PlayClientEffectObjectMessage;
import com.projectswg.common.network.packets.swg.zone.object_controller.ShowFlyText;
import com.projectswg.common.network.packets.swg.zone.object_controller.ShowFlyText.Scale;
import com.projectswg.common.network.packets.swg.zone.object_controller.combat.CombatAction;
Expand Down Expand Up @@ -157,15 +158,25 @@ static void addBuff(CreatureObject caster, CreatureObject receiver, String buffN
new BuffIntent(buffName, caster, receiver, false).broadcast();
}

public static void handleStatus(CreatureObject source, CombatStatus status) {
public static void handleStatus(CreatureObject source, CombatCommand combatCommand, CombatStatus status) {
switch (status) {
case NO_TARGET -> showFlyText(source, "@combat_effects:target_invalid_fly", Scale.MEDIUM, SWGColor.Whites.INSTANCE.getWhite(), ShowFlyText.Flag.PRIVATE);
case TOO_FAR -> showFlyText(source, "@combat_effects:range_too_far", Scale.MEDIUM, SWGColor.Blues.INSTANCE.getCyan(), ShowFlyText.Flag.PRIVATE);
case INVALID_TARGET -> showFlyText(source, "@combat_effects:target_invalid_fly", Scale.MEDIUM, SWGColor.Blues.INSTANCE.getCyan(), ShowFlyText.Flag.PRIVATE);
case TOO_TIRED -> showFlyText(source, "@combat_effects:action_too_tired", Scale.MEDIUM, SWGColor.Oranges.INSTANCE.getOrange(), ShowFlyText.Flag.PRIVATE);
case SUCCESS -> showTriggerEffect(source, combatCommand);
default -> showFlyText(source, "@combat_effects:action_failed", Scale.MEDIUM, SWGColor.Whites.INSTANCE.getWhite(), ShowFlyText.Flag.PRIVATE);
}
}

private static void showTriggerEffect(CreatureObject source, CombatCommand command) {
String triggerEffect = command.getTriggerEffect();
if (triggerEffect.length() > 0) {
String triggerEffectHardpoint = command.getTriggerEffectHardpoint();
source.sendObservers(new PlayClientEffectObjectMessage(triggerEffect, triggerEffectHardpoint, source.getObjectId(), ""));
}
}

static void showFlyText(TangibleObject obj, String text, Scale scale, RGB c, ShowFlyText.Flag... flags) {
obj.sendSelf(new ShowFlyText(obj.getObjectId(), text, scale, c, flags));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.projectswg.holocore.services.gameplay.combat.command

import com.projectswg.common.data.combat.CombatStatus
import com.projectswg.holocore.resources.gameplay.combat.CombatStatus
import com.projectswg.holocore.intents.gameplay.combat.EnterCombatIntent
import com.projectswg.holocore.resources.support.global.commands.CombatCommand
import com.projectswg.holocore.resources.support.objects.swg.SWGObject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

package com.projectswg.holocore.services.gameplay.combat.command;

import com.projectswg.common.data.combat.CombatStatus;
import com.projectswg.holocore.resources.gameplay.combat.CombatStatus;
import com.projectswg.common.data.location.Location;
import com.projectswg.common.network.packets.swg.zone.PlayClientEffectObjectMessage;
import com.projectswg.holocore.intents.support.objects.swg.DestroyObjectIntent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@

package com.projectswg.holocore.services.gameplay.combat.command

import com.projectswg.common.data.combat.CombatStatus
import com.projectswg.holocore.resources.gameplay.combat.CombatStatus
import com.projectswg.common.data.combat.HitType
import com.projectswg.common.network.packets.swg.zone.PlayClientEffectObjectMessage
import com.projectswg.holocore.resources.support.global.commands.CombatCommand
import com.projectswg.holocore.resources.support.objects.swg.SWGObject
import com.projectswg.holocore.resources.support.objects.swg.creature.CreatureObject
Expand Down Expand Up @@ -64,16 +63,19 @@ class CombatCommandHandler {
fun executeCombatCommand(source: CreatureObject, target: SWGObject?, command: CombatCommand, arguments: String): CombatStatus {
val equippedWeapon = source.equippedWeapon
val specialAttackCost = equippedWeapon.specialAttackCost
source.modifyHealth((-command.healthCost).toInt())
source.modifyAction((-command.actionCost * specialAttackCost / 100).toInt())
source.modifyMind((-command.mindCost * specialAttackCost / 100).toInt())
val healthCost = command.healthCost.toInt()
val actionCost = (command.actionCost * specialAttackCost / 100).toInt()
val mindCost = (command.mindCost * specialAttackCost / 100).toInt()

val hitType = hitTypeMap[command.hitType]

if (command.triggerEffect.isNotEmpty()) {
val triggerEffect = PlayClientEffectObjectMessage(command.triggerEffect, command.triggerEffectHardpoint, source.objectId, "")
source.sendSelf(triggerEffect)
if (healthCost > source.health || actionCost > source.action || mindCost > source.mind) {
return CombatStatus.TOO_TIRED
}

source.modifyHealth(-healthCost)
source.modifyAction(-actionCost)
source.modifyMind(-mindCost)

val hitType = hitTypeMap[command.hitType]

return hitType?.handle(source, target, command, arguments) ?: CombatStatus.UNKNOWN
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import com.projectswg.common.network.packets.swg.zone.object_controller.combat.CombatAction.Defender;
import com.projectswg.common.network.packets.swg.zone.object_controller.combat.CombatSpam;
import com.projectswg.holocore.intents.gameplay.player.experience.ExperienceIntent;
import com.projectswg.holocore.resources.gameplay.combat.CombatStatus;
import com.projectswg.holocore.resources.support.color.SWGColor;
import com.projectswg.holocore.resources.support.global.commands.CombatCommand;
import com.projectswg.holocore.resources.support.objects.swg.SWGObject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

package com.projectswg.holocore.services.gameplay.combat.command;

import com.projectswg.common.data.combat.CombatStatus;
import com.projectswg.holocore.resources.gameplay.combat.CombatStatus;
import com.projectswg.holocore.resources.support.global.commands.CombatCommand;
import com.projectswg.holocore.resources.support.objects.swg.SWGObject;
import com.projectswg.holocore.resources.support.objects.swg.creature.CreatureObject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.projectswg.common.data.CRC;
import com.projectswg.common.data.combat.AttackType;
import com.projectswg.common.data.combat.CombatStatus;
import com.projectswg.holocore.resources.gameplay.combat.CombatStatus;
import com.projectswg.common.data.combat.HitType;
import com.projectswg.common.data.encodables.oob.StringId;
import com.projectswg.common.network.packets.SWGPacket;
Expand Down Expand Up @@ -217,7 +217,7 @@ private void executeCommandNow(EnqueuedCommand command) {
command.getArguments());

if (combatStatus != CombatStatus.SUCCESS) {
CombatCommandCommon.handleStatus(command.getSource(), combatStatus);
CombatCommandCommon.handleStatus(command.getSource(), combatCommand, combatStatus);
sendCommandFailed(command);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import com.projectswg.holocore.intents.support.global.network.InboundPacketInten
import com.projectswg.holocore.intents.support.objects.swg.ObjectCreatedIntent
import com.projectswg.holocore.resources.support.objects.ObjectCreator
import com.projectswg.holocore.resources.support.objects.swg.weapon.DefaultWeaponFactory
import com.projectswg.holocore.services.gameplay.combat.buffs.BuffService
import com.projectswg.holocore.services.support.global.commands.CommandExecutionService
import com.projectswg.holocore.services.support.global.commands.CommandQueueService
import com.projectswg.holocore.test.resources.GenericCreatureObject
import com.projectswg.holocore.test.resources.GenericPlayer
import com.projectswg.holocore.test.runners.TestRunnerSimulatedWorld
import org.junit.jupiter.api.Assertions.assertFalse
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
Expand All @@ -19,6 +21,7 @@ class AttackCostTest : TestRunnerSimulatedWorld() {

@BeforeEach
fun setup() {
registerService(BuffService())
registerService(CommandQueueService())
registerService(CommandExecutionService())
registerService(CombatStatusService())
Expand Down Expand Up @@ -54,6 +57,39 @@ class AttackCostTest : TestRunnerSimulatedWorld() {
assertTrue(creatureObject.mind < creatureObject.maxMind)
}

@Test
fun `too tired when combat command requires too much health`() {
val creatureObject = createCreatureObject()
creatureObject.health = 1
val player = creatureObject.owner ?: throw RuntimeException("Unable to access player")

burstRun(player)

assertFalse(creatureObject.hasBuff("burstRun"))
}

@Test
fun `too tired when combat command requires too much action`() {
val creatureObject = createCreatureObject()
creatureObject.action = 1
val player = creatureObject.owner ?: throw RuntimeException("Unable to access player")

burstRun(player)

assertFalse(creatureObject.hasBuff("burstRun"))
}

@Test
fun `too tired when combat command requires too much mind`() {
val creatureObject = createCreatureObject()
creatureObject.mind = 1
val player = creatureObject.owner ?: throw RuntimeException("Unable to access player")

burstRun(player)

assertFalse(creatureObject.hasBuff("burstRun"))
}

private fun burstRun(player: GenericPlayer) {
val crc = CRC.getCrc("burstrun")

Expand Down