Files
Server/src/engine/net/client/handlers/ObjectActionMsgHandler.java
T

287 lines
12 KiB
Java
Raw Normal View History

2022-04-30 09:41:17 -04:00
package engine.net.client.handlers;
import engine.gameManager.*;
import engine.math.Bounds;
import engine.math.Vector3fImmutable;
import engine.mbEnums;
2022-04-30 09:41:17 -04:00
import engine.net.Dispatch;
import engine.net.client.ClientConnection;
import engine.net.client.msg.*;
import engine.objects.*;
import engine.powers.PowersBase;
import java.util.ArrayList;
import java.util.concurrent.locks.ReentrantReadWriteLock;
/*
* @Author:
2024-03-14 07:36:36 -04:00
* @Summary: Processes application protocol message which handles
* items in the character's inventory which are used. Potions, Deeds, etc.
2022-04-30 09:41:17 -04:00
*/
2024-03-14 07:36:36 -04:00
2022-04-30 09:41:17 -04:00
public class ObjectActionMsgHandler extends AbstractClientMsgHandler {
2023-07-15 09:23:48 -04:00
// Reentrant lock for dropping banes
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public ObjectActionMsgHandler() {
2024-05-12 11:55:12 -04:00
super();
2023-07-15 09:23:48 -04:00
}
2024-03-24 09:42:27 -04:00
2023-07-15 09:23:48 -04:00
@Override
2024-05-12 13:42:11 -04:00
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) {
2023-07-15 09:23:48 -04:00
// Member variable declaration
ObjectActionMsg msg;
PlayerCharacter player;
CharacterItemManager itemMan;
ArrayList<Long> comps;
Dispatch dispatch;
boolean waterbucketBypass = false;
// Member variable assignment
msg = (ObjectActionMsg) baseMsg;
player = SessionManager.getPlayerCharacter(origin);
if (player == null) {
return true;
}
2024-03-18 10:01:29 -04:00
itemMan = player.charItemManager;
2023-07-15 09:23:48 -04:00
if (itemMan == null) {
return true;
}
comps = msg.getTargetCompID();
if (comps.isEmpty()) {
return true;
}
long comp = comps.get(0);
if (((int) comp) != 0) {
Item item = Item.getFromCache((int) comp);
if (item == null) {
return true;
}
//dupe check
if (!item.validForInventory(origin, player, itemMan)) {
return true;
}
if (itemMan.doesCharOwnThisItem(item.getObjectUUID())) {
2024-03-15 10:35:41 -04:00
int uuid = item.templateID;
2023-07-15 09:23:48 -04:00
2024-03-24 09:42:27 -04:00
switch (item.template.item_type) {
2023-07-15 09:23:48 -04:00
2024-03-24 09:42:27 -04:00
case DEED: //buildings
//Call add building screen here, ib.getUseID() get's building ID
2023-07-15 09:23:48 -04:00
2024-03-24 09:42:27 -04:00
//if inside player city, center loc on tol. otherwise center on player.
Vector3fImmutable loc = player.getLoc();
Zone zone = ZoneManager.findSmallestZone(player.getLoc());
2023-07-15 09:23:48 -04:00
2024-03-24 09:42:27 -04:00
if (zone != null) {
if (zone.guild_zone) {
loc = zone.getLoc();
2023-07-15 09:23:48 -04:00
}
2024-03-24 09:42:27 -04:00
}
PlaceAssetMsg pam = new PlaceAssetMsg();
pam.setActionType(2);
pam.setContractID(item.getObjectUUID());
pam.setX(loc.getX() + 64); //offset grid from tol
pam.setY(loc.getY());
pam.setZ(loc.getZ() + 64); //offset grid from tol
pam.addPlacementInfo(item.template.deed_structure_id);
dispatch = Dispatch.borrow(player, pam);
DispatchManager.dispatchMsgDispatch(dispatch, mbEnums.DispatchChannel.SECONDARY);
2024-03-24 09:42:27 -04:00
//itemMan.consume(item); //temporary fix for dupe.. TODO Make Item Unusable after This message is sent.
break;
case FURNITUREDEED: //furniture
//Call add furniture screen here. ib.getUseID() get's furniture ID
break;
case OFFERING:
long shrineCompID = comps.get(1);
Building shrineBuilding = BuildingManager.getBuilding((int) shrineCompID);
if (shrineBuilding == null) {
return true;
}
if (shrineBuilding.getBlueprint() != null && shrineBuilding.getBlueprint().getBuildingGroup() != mbEnums.BuildingGroup.SHRINE) {
2024-03-24 09:42:27 -04:00
return true;
}
if (shrineBuilding.getRank() == -1) {
return true;
}
Shrine shrine = Shrine.shrinesByBuildingUUID.get(shrineBuilding.getObjectUUID());
if (shrine == null) {
return true;
}
if (shrine.addFavor(player, item)) {
shrineBuilding.addEffectBit(1000000 << 2);
shrineBuilding.updateEffects();
shrineBuilding.removeEffectBit(1000000 << 2);
}
break;
case REALMCHARTER:
int charterType = 0;
switch (uuid) {
case 910020:
charterType = 762228431;
break;
case 910021:
charterType = -15978914;
break;
case 910022:
charterType = -600065291;
break;
}
if (Realm.claimRealm(player, charterType) == true) {
itemMan.consume(item);
}
break;
case WAND: //rod of command
long compID = comps.get(1);
int objectType = AbstractWorldObject.extractTypeID(compID).ordinal();
Mob toCommand;
if (objectType == mbEnums.GameObjectType.Mob.ordinal()) {
2024-03-24 09:42:27 -04:00
toCommand = Mob.getFromCache((int) compID);
} //Only Command Mob Types.
else {
return true;
}
if (toCommand == null) {
return true;
}
if (!toCommand.isSiege())
return true;
if (player.commandSiegeMinion(toCommand)) {
itemMan.consume(item);
}
break;
//ANNIVERSERY GIFT
case TREASURE:
// *** Disabled for now: Needs bootyset created
LootManager.peddleFate(player, item);
break;
case BUCKET: //water bucket
case POTION: //potions, tears of saedron
case SCROLL: //runes, petition, warrant, scrolls
if (uuid > 680069 && uuid < 680074) //Handle Charter, Deed, Petition, Warrant here
2024-03-24 09:42:27 -04:00
break;
2023-07-15 09:23:48 -04:00
2024-04-27 07:06:39 -04:00
if (item.template.item_bane_rank > 0) {
2023-07-15 09:23:48 -04:00
2024-03-24 09:42:27 -04:00
// Only one banestone at a time
2024-04-27 07:06:39 -04:00
2024-03-24 09:42:27 -04:00
lock.writeLock().lock();
2023-07-15 09:23:48 -04:00
2024-03-24 09:42:27 -04:00
try {
2024-04-27 07:06:39 -04:00
if (Bane.summonBanestone(player, origin, item.template.item_bane_rank) == true)
2024-03-24 09:42:27 -04:00
itemMan.consume(item);
} finally {
lock.writeLock().unlock();
2023-07-15 09:23:48 -04:00
}
break;
2024-04-27 07:06:39 -04:00
}
if (uuid == 910010) { //tears of saedron
2024-04-27 07:07:59 -04:00
if (comps.size() > 1)
2024-03-24 09:42:27 -04:00
AbstractCharacter.removeRune(player, origin, comps.get(1).intValue());
2023-07-15 09:23:48 -04:00
break;
2024-04-27 07:06:39 -04:00
}
if (item.chargesRemaining > 0) {
2024-03-24 09:42:27 -04:00
ArrayList<Long> tarList = msg.getTargetCompID();
AbstractWorldObject target = player;
2024-04-27 07:06:39 -04:00
2024-03-24 09:42:27 -04:00
if (tarList.size() > 1) {
long tarID = tarList.get(1);
2024-04-27 07:06:39 -04:00
2024-03-24 09:42:27 -04:00
if (tarID != 0) {
AbstractGameObject tarAgo = AbstractGameObject.getFromTypeAndID(tarID);
2024-04-27 07:06:39 -04:00
if (tarAgo instanceof AbstractWorldObject) {
2024-03-24 09:42:27 -04:00
target = (AbstractWorldObject) tarAgo;
2023-07-15 09:23:48 -04:00
}
}
2024-03-24 09:42:27 -04:00
}
2023-07-15 09:23:48 -04:00
2024-03-24 09:42:27 -04:00
// Bypass for waterbuckets
2023-07-15 09:23:48 -04:00
if (item.template.item_type.equals(mbEnums.ItemType.BUCKET)) {
2023-07-15 09:23:48 -04:00
2024-03-24 09:42:27 -04:00
// test for valid target type
if (target.getObjectType() == mbEnums.GameObjectType.PlayerCharacter)
2024-03-24 09:42:27 -04:00
waterbucketBypass = true;
else {
// test distance to structure
Building targetBuilding = (Building) target;
Bounds testBounds = Bounds.borrow();
testBounds.setBounds(player.getLoc(), 25);
2023-07-15 09:23:48 -04:00
2024-03-24 09:42:27 -04:00
if (Bounds.collide(targetBuilding.getBounds(), testBounds, .1f) == false) {
ChatManager.chatSystemError(player, "Not in range of structura for to heal!");
return true;
2023-07-15 09:23:48 -04:00
}
}
2024-03-24 09:42:27 -04:00
// Send piss bucket animation
2023-07-15 09:23:48 -04:00
2024-03-24 09:42:27 -04:00
VisualUpdateMessage vum = new VisualUpdateMessage(player, 16323);
vum.configure();
DispatchManager.sendToAllInRange(player, vum);
2024-03-24 09:42:27 -04:00
}
if (waterbucketBypass == false) {
String powerString = item.template.item_power_grant.keySet().iterator().next();
2024-03-24 09:42:27 -04:00
PowersBase powerAction = PowersManager.powersBaseByIDString.get(powerString);
int powerValue = item.template.item_power_grant.get(powerString);
2024-03-24 09:42:27 -04:00
PowersManager.applyPower(player, target, Vector3fImmutable.ZERO, powerAction.getToken(), powerValue, true);
}
itemMan.consume(item);
} else //just remove the item at this point
itemMan.consume(item);
dispatch = Dispatch.borrow(player, msg);
DispatchManager.dispatchMsgDispatch(dispatch, mbEnums.DispatchChannel.SECONDARY);
2024-03-24 09:42:27 -04:00
player.cancelOnSpell();
break;
case RUNE:
2024-06-22 19:31:13 -05:00
if(ApplyRuneMsg.applyRune(uuid, origin, player)) {
itemMan.consume(item);
}
break;
2024-03-24 09:42:27 -04:00
default: //shouldn't be here, consume item
dispatch = Dispatch.borrow(player, msg);
DispatchManager.dispatchMsgDispatch(dispatch, mbEnums.DispatchChannel.SECONDARY);
2024-03-24 09:42:27 -04:00
// itemMan.consume(item);
}
2023-07-15 09:23:48 -04:00
} else {
// TODO log item does not belong to player
// System.out.println("Item does not belong to player");
// Cleanup duped item here
}
}
return true;
}
2022-04-30 09:41:17 -04:00
}