Merge branch 'quality_assurance' of https://bitbucket.org/tacef/holocore into quality_assurance

This commit is contained in:
Tacef Ine
2017-07-09 19:36:57 +02:00
12 changed files with 136 additions and 14 deletions
@@ -2,6 +2,7 @@ import com.projectswg.common.data.location.Location
import com.projectswg.common.data.location.Terrain
import intents.object.CreateStaticItemIntent
import intents.object.ObjectTeleportIntent
import resources.containers.ContainerPermissionsType;
import resources.objects.SWGObject
import resources.objects.creature.CreatureObject
import resources.player.Player
@@ -52,7 +53,7 @@ static def spawnItems(Player player, List<String> items) {
def creature = player.getCreatureObject()
def inventory = creature.getSlottedObject("inventory")
new CreateStaticItemIntent(creature, inventory, new StaticItemService.LootBoxHandler(creature), items.toArray(new String[0])).broadcast()
new CreateStaticItemIntent(creature, inventory, new StaticItemService.LootBoxHandler(creature), ContainerPermissionsType.DEFAULT, items.toArray(new String[items.size()])).broadcast()
}
static def handleArmor(Player player) {
@@ -29,6 +29,7 @@ package intents.object;
import com.projectswg.common.control.Intent;
import resources.containers.ContainerPermissionsType;
import resources.objects.SWGObject;
import services.objects.StaticItemService.ObjectCreationHandler;
@@ -37,12 +38,14 @@ public final class CreateStaticItemIntent extends Intent {
private final SWGObject requester;
private final SWGObject container;
private final ObjectCreationHandler objectCreationHandler;
private final ContainerPermissionsType permissions;
private final String[] itemNames;
public CreateStaticItemIntent(SWGObject requester, SWGObject container, ObjectCreationHandler objectCreationHandler, String... itemNames) {
public CreateStaticItemIntent(SWGObject requester, SWGObject container, ObjectCreationHandler objectCreationHandler, ContainerPermissionsType permissions, String... itemNames) {
this.requester = requester;
this.container = container;
this.objectCreationHandler = objectCreationHandler;
this.permissions = permissions;
this.itemNames = itemNames;
}
@@ -58,6 +61,10 @@ public final class CreateStaticItemIntent extends Intent {
return requester;
}
public ContainerPermissionsType getPermissions(){
return permissions;
}
public ObjectCreationHandler getObjectCreationHandler() {
return objectCreationHandler;
}
@@ -42,6 +42,7 @@ import intents.object.MoveObjectIntent;
import intents.object.ObjectTeleportIntent;
import intents.player.DeleteCharacterIntent;
import resources.commands.ICmdCallback;
import resources.containers.ContainerPermissionsType;
import resources.network.DisconnectReason;
import resources.objects.SWGObject;
import resources.objects.creature.CreatureObject;
@@ -163,7 +164,7 @@ public class QaToolCmdCallback implements ICmdCallback {
public boolean isIgnoreVolume() {
return false;
}
}, itemName).broadcast();
}, ContainerPermissionsType.DEFAULT, itemName).broadcast();
}
private void forceDelete(final ObjectManager objManager, final Player player, final SWGObject target) {
@@ -32,6 +32,7 @@ import resources.objects.SWGObject;
public enum ContainerPermissionsType {
DEFAULT (new DefaultPermissions()),
INVENTORY (new InventoryPermissions()),
LOOT (new LootPermissions()),
ADMIN (new AdminPermissions());
private final ContainerPermissions permissions;
@@ -0,0 +1,80 @@
/*******************************************************************************
* Copyright (c) 2015 /// 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 resources.containers;
import com.projectswg.common.debug.Log;
import resources.objects.SWGObject;
import resources.objects.creature.CreatureObject;
class LootPermissions extends ContainerPermissions {
@Override
public boolean canView(SWGObject requester, SWGObject container) {
return true;
}
@Override
public boolean canEnter(SWGObject requester, SWGObject container) {
return true;
}
@Override
public boolean canRemove(SWGObject requester, SWGObject container) {
return false;
}
@Override
public boolean canMove(SWGObject requester, SWGObject container) {
//TODO: Group Permissions
if (requester.getOwner() == null || requester.getParent() == null)
return true;
if (container.getParent() == null || requester.getParent() == null)
return defaultCanMove(requester, container);
if (!(container.getParent().getParent() instanceof CreatureObject))
return defaultCanMove(requester, container);
CreatureObject highestDamageDealer = ((CreatureObject) container.getParent().getParent()).getHighestDamageDealer();
if (highestDamageDealer != null && highestDamageDealer.getOwner() != null && highestDamageDealer.getOwner().equals(requester.getOwner()))
return true;
return defaultCanMove(requester, container);
}
@Override
public boolean canAdd(SWGObject requester, SWGObject container) {
return false;
}
private boolean defaultCanMove(SWGObject requester, SWGObject container){
return requester.getOwner() != null && requester.getOwner().equals(container.getOwner());
}
}
@@ -30,8 +30,10 @@ package resources.objects.creature;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.function.Predicate;
import java.util.stream.Stream;
@@ -67,8 +69,9 @@ public class CreatureObject extends TangibleObject {
private transient long lastReserveOperation = 0;
private final CreatureObjectClientServerNP creo4 = new CreatureObjectClientServerNP();
private final CreatureObjectSharedNP creo6 = new CreatureObjectSharedNP();
private final CreatureObjectClientServerNP creo4 = new CreatureObjectClientServerNP();
private final CreatureObjectSharedNP creo6 = new CreatureObjectSharedNP();
private final Map<CreatureObject, Integer> damageMap = new HashMap<>();
private Posture posture = Posture.UPRIGHT;
private Race race = Race.HUMAN_MALE;
@@ -855,6 +858,25 @@ public class CreatureObject extends TangibleObject {
}
return items;
}
public Map<CreatureObject, Integer> getDamageMap(){
return Collections.unmodifiableMap(damageMap);
}
public CreatureObject getHighestDamageDealer(){
synchronized (damageMap){
return damageMap.keySet().stream().max((c1, c2) -> damageMap.get(c1) - damageMap.get(c2)).orElse(null);
}
}
public void handleDamage(CreatureObject attacker, int damage){
synchronized (damageMap){
if(damageMap.containsKey(attacker))
damageMap.put(attacker, damageMap.get(attacker) + damage);
else
damageMap.put(attacker, damage);
}
}
public boolean isAttackable(CreatureObject otherObject) {
Posture otherPosture = otherObject.getPosture();
+6 -1
View File
@@ -426,6 +426,8 @@ public class CombatManager extends Manager {
action.addDefender(target, true, (byte) 0, HitLocation.HIT_LOCATION_BODY, (short) finalDamage);
target.handleDamage(source, finalDamage);
if (target.getHealth() <= finalDamage)
doCreatureDeath(target, source);
else
@@ -546,8 +548,11 @@ public class CombatManager extends Manager {
}
private void killCreature(CreatureObject killer, CreatureObject corpse) {
// We don't want to kill a creature that is already dead
if (corpse.getPosture() == Posture.DEAD)
return;
corpse.setPosture(Posture.DEAD);
Log.i("%s was killed by %s", corpse, killer);
new CreatureKilledIntent(killer, corpse).broadcast();
}
+4 -5
View File
@@ -47,6 +47,7 @@ import intents.radial.RadialResponseIntent;
import intents.radial.RadialSelectionIntent;
import network.packets.swg.zone.ClientOpenContainerMessage;
import network.packets.swg.zone.PlayClientEffectObjectTransformMessage;
import resources.containers.ContainerPermissionsType;
import resources.objects.SWGObject;
import resources.objects.creature.CreatureDifficulty;
import resources.objects.creature.CreatureObject;
@@ -199,7 +200,6 @@ public final class LootService extends Service {
SWGObject lootInventory = ObjectCreator.createObjectFromTemplate("object/tangible/inventory/shared_creature_inventory.iff");
lootInventory.setLocation(corpse.getLocation());
// TODO set permissions on lootInventory
corpse.addObject(lootInventory); // It's a slotted object and goes in the inventory slot
new ObjectCreatedIntent(lootInventory).broadcast();
@@ -355,7 +355,7 @@ public final class LootService extends Service {
} else if (randomItemName.endsWith(".iff")) {
String sharedTemplate = ClientFactory.formatToSharedFile(randomItemName);
SWGObject object = ObjectCreator.createObjectFromTemplate(sharedTemplate);
object.setContainerPermissions(ContainerPermissionsType.LOOT);
object.moveToContainer(lootInventory);
new ObjectCreatedIntent(object).broadcast();
} else {
@@ -369,14 +369,13 @@ public final class LootService extends Service {
public boolean isIgnoreVolume() {
return true;
}
}, randomItemName).broadcast();
},ContainerPermissionsType.LOOT, randomItemName).broadcast();
}
break; // Only one group is ever spawned
}
}
}
private static class NPCLoot {
private final int minCash;
@@ -454,7 +454,7 @@ public class EntertainmentService extends Service {
PerformanceData performanceData = performanceMap.get(performanceName);
int flourishXpMod = performanceData.getFlourishXpMod();
int performanceCounter = performer.getPerformanceCounter();
int xpGained = (int) (performanceCounter * (flourishXpMod * 3.8));
int xpGained = (int) (performanceCounter * flourishXpMod);
if(xpGained > 0) {
new ExperienceIntent(performer, "entertainer", xpGained).broadcast();
@@ -49,6 +49,7 @@ import network.packets.swg.zone.PlayMusicMessage;
import network.packets.swg.zone.object_controller.ShowFlyText;
import network.packets.swg.zone.object_controller.ShowFlyText.Scale;
import resources.Race;
import resources.containers.ContainerPermissionsType;
import resources.encodables.StringId;
import resources.objects.SWGObject;
import resources.objects.creature.CreatureObject;
@@ -196,7 +197,7 @@ public final class SkillTemplateService extends Service {
// No reason to broadcast this intent if we don't need new static items anyways
if (!staticItems.isEmpty())
new CreateStaticItemIntent(creatureObject, inventory, new StaticItemService.LootBoxHandler(creatureObject), staticItems.toArray(new String[staticItems.size()])).broadcast();
new CreateStaticItemIntent(creatureObject, inventory, new StaticItemService.LootBoxHandler(creatureObject), ContainerPermissionsType.DEFAULT, staticItems.toArray(new String[staticItems.size()])).broadcast();
}
}
@@ -45,6 +45,7 @@ import intents.server.ConfigChangedIntent;
import network.packets.swg.zone.object_controller.ShowLootBox;
import resources.combat.DamageType;
import resources.config.ConfigFile;
import resources.containers.ContainerPermissionsType;
import resources.objects.SWGObject;
import resources.objects.creature.CreatureObject;
import resources.objects.weapon.WeaponObject;
@@ -168,6 +169,7 @@ public final class StaticItemService extends Service {
String[] itemNames = csii.getItemNames();
Player requesterOwner = csii.getRequester().getOwner();
ObjectCreationHandler objectCreationHandler = csii.getObjectCreationHandler();
ContainerPermissionsType permissions = csii.getPermissions();
// If adding these items to the container would exceed the max capacity...
if(!objectCreationHandler.isIgnoreVolume() && container.getVolume() + itemNames.length > container.getMaxContainerSize()) {
@@ -196,6 +198,8 @@ public final class StaticItemService extends Service {
case SUCCESS:
Log.d("Successfully moved %s into container %s", itemName, container);
createdObjects[j] = object;
object.setContainerPermissions(permissions);
break;
default:
break;
+2 -1
View File
@@ -41,6 +41,7 @@ import com.projectswg.common.debug.Log;
import intents.object.CreateStaticItemIntent;
import intents.object.DestroyObjectIntent;
import intents.radial.RadialSelectionIntent;
import resources.containers.ContainerPermissionsType;
import resources.objects.SWGObject;
import resources.objects.creature.CreatureObject;
import resources.player.Player;
@@ -113,7 +114,7 @@ public class UniformBoxService extends Service {
staticItems.add(item);
}
new CreateStaticItemIntent(creature, inventory, new StaticItemService.LootBoxHandler(creature), staticItems.toArray(new String[staticItems.size()])).broadcast();
new CreateStaticItemIntent(creature, inventory, new StaticItemService.LootBoxHandler(creature), ContainerPermissionsType.DEFAULT, staticItems.toArray(new String[staticItems.size()])).broadcast();
}
}