Handler created for LootMsg
This commit is contained in:
@@ -32,8 +32,6 @@ import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
import static engine.math.FastMath.sqr;
|
||||
|
||||
/**
|
||||
* @author:
|
||||
* @summary: This class is the mainline router for application protocol
|
||||
@@ -178,235 +176,6 @@ public class ClientMessagePump implements NetMsgHandler {
|
||||
JobScheduler.getInstance().scheduleJob(new RefreshGroupJob(sourcePlayer), MBServerStatics.LOAD_OBJECT_DELAY);
|
||||
}
|
||||
|
||||
private static void loot(LootMsg msg, ClientConnection origin) throws MsgSendException {
|
||||
|
||||
PlayerCharacter player = SessionManager.getPlayerCharacter(origin);
|
||||
if (player == null)
|
||||
return;
|
||||
|
||||
if (!player.isAlive())
|
||||
return;
|
||||
|
||||
Item item = msg.getItem();
|
||||
|
||||
if (item == null)
|
||||
return;
|
||||
|
||||
if (item.lootLock.tryLock()) {
|
||||
try {
|
||||
Item itemRet = null;
|
||||
// get current owner
|
||||
int targetType = msg.getTargetType();
|
||||
int targetID = msg.getTargetID();
|
||||
|
||||
if (targetType == GameObjectType.PlayerCharacter.ordinal() || targetType == GameObjectType.Mob.ordinal() || targetType == GameObjectType.Corpse.ordinal()) {
|
||||
} else { //needed for getting contracts for some reason
|
||||
targetType = msg.getSourceID2();
|
||||
targetID = msg.getUnknown01();
|
||||
}
|
||||
|
||||
//can't loot while flying
|
||||
if (player.getAltitude() > 0)
|
||||
return;
|
||||
|
||||
AbstractCharacter tar = null;
|
||||
Corpse corpse = null;
|
||||
|
||||
if (targetType == GameObjectType.PlayerCharacter.ordinal() || targetType == GameObjectType.Mob.ordinal()) {
|
||||
|
||||
if (targetType == GameObjectType.PlayerCharacter.ordinal()) {
|
||||
tar = PlayerCharacter.getFromCache(targetID);
|
||||
|
||||
if (tar == null)
|
||||
return;
|
||||
|
||||
if (player.getObjectUUID() != tar.getObjectUUID() && ((PlayerCharacter) tar).isInSafeZone())
|
||||
return;
|
||||
|
||||
} else if (targetType == GameObjectType.NPC.ordinal())
|
||||
tar = NPC.getFromCache(targetID);
|
||||
else if (targetType == GameObjectType.Mob.ordinal())
|
||||
tar = Mob.getFromCache(targetID);
|
||||
if (tar == null)
|
||||
return;
|
||||
|
||||
if (tar.equals(player)) {
|
||||
ErrorPopupMsg.sendErrorMsg(player, "Cannot loot this item.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (player.getLoc().distanceSquared2D(tar.getLoc()) > sqr(MBServerStatics.LOOT_RANGE)) {
|
||||
ErrorPopupMsg.sendErrorMsg(player, "You are too far away to loot this corpse.");
|
||||
|
||||
Logger.info(player.getFirstName() + " tried looting at " + player.getLoc().distance2D(tar.getLoc()) + " distance.");
|
||||
return;
|
||||
}
|
||||
|
||||
//can't loot from someone who is alive.
|
||||
if (AbstractWorldObject.IsAbstractCharacter(tar)) {
|
||||
if (tar.isAlive())
|
||||
return;
|
||||
// Logger.error("WorldServer.loot", "Looting from live player");
|
||||
}
|
||||
|
||||
if (!GroupManager.goldSplit(player, item, origin, tar)) {
|
||||
|
||||
if (tar.charItemManager != null) {
|
||||
|
||||
itemRet = tar.charItemManager.lootItemFromMe(item, player, origin);
|
||||
|
||||
//Take equipment off mob
|
||||
if (tar.getObjectType() == GameObjectType.Mob && itemRet != null) {
|
||||
Mob mobTarget = (Mob) tar;
|
||||
|
||||
if (item != null && item.getObjectType() == GameObjectType.MobLoot) {
|
||||
|
||||
for (Item equip : mobTarget.charItemManager.equipped.values()) {
|
||||
|
||||
TransferItemFromEquipToInventoryMsg back = new TransferItemFromEquipToInventoryMsg(mobTarget, equip.equipSlot);
|
||||
DispatchMessage.dispatchMsgToInterestArea(mobTarget, back, DispatchChannel.SECONDARY, MBServerStatics.CHARACTER_LOAD_RANGE, false, false);
|
||||
|
||||
LootMsg lootMsg = new LootMsg(0, 0, tar.getObjectType().ordinal(), tar.getObjectUUID(), equip);
|
||||
Dispatch dispatch = Dispatch.borrow(player, lootMsg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} else if (targetType == GameObjectType.Corpse.ordinal()) {
|
||||
corpse = Corpse.getCorpse(targetID);
|
||||
if (corpse == null)
|
||||
return;
|
||||
|
||||
if (player.getLoc().distanceSquared2D(corpse.getLoc()) > sqr(MBServerStatics.LOOT_RANGE)) {
|
||||
ErrorPopupMsg.sendErrorMsg(player, "You are too far away to loot this corpse.");
|
||||
|
||||
Logger.info(player.getFirstName() + " tried looting at " + player.getLoc().distance2D(corpse.getLoc()) + " distance.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
//can't loot other players in safe zone.
|
||||
if (corpse.getBelongsToType() == GameObjectType.PlayerCharacter.ordinal()) {
|
||||
|
||||
if (player.getObjectUUID() == corpse.getBelongsToID())
|
||||
itemRet = corpse.lootItem(item, player);
|
||||
else if (!GroupManager.goldSplit(player, item, origin, corpse)) {
|
||||
itemRet = corpse.lootItem(item, player);
|
||||
|
||||
}
|
||||
|
||||
if (itemRet == null)
|
||||
return;
|
||||
|
||||
|
||||
if (item.template.item_type.equals(engine.Enum.ItemType.GOLD)) {
|
||||
// this is done to prevent the temporary goldItem item
|
||||
// (from the mob) from appearing in player's inventory.
|
||||
// It also updates the goldItem quantity display
|
||||
UpdateGoldMsg updateTargetGold = null;
|
||||
|
||||
|
||||
if (corpse != null)
|
||||
updateTargetGold = new UpdateGoldMsg(corpse);
|
||||
|
||||
updateTargetGold.configure();
|
||||
DispatchMessage.dispatchMsgToInterestArea(corpse, updateTargetGold, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, false, false);
|
||||
|
||||
UpdateGoldMsg ugm = new UpdateGoldMsg(player);
|
||||
ugm.configure();
|
||||
Dispatch dispatch = Dispatch.borrow(player, ugm);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
|
||||
|
||||
// respond back loot message. Try sending to everyone.
|
||||
|
||||
} else {
|
||||
|
||||
DispatchMessage.dispatchMsgToInterestArea(corpse, msg, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, false, true);
|
||||
|
||||
|
||||
//player.getCharItemManager().updateInventory();
|
||||
}
|
||||
|
||||
//TODO send group loot message if player is grouped and visible
|
||||
Group group = GroupManager.getGroup(player);
|
||||
|
||||
if (group != null && group.getSplitGold() && (item.template.item_type.equals(engine.Enum.ItemType.GOLD) == false)) {
|
||||
String name = item.getName();
|
||||
String text = player.getFirstName() + " has looted " + name + '.';
|
||||
ChatManager.chatGroupInfoCanSee(player, text);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
} else
|
||||
return;
|
||||
|
||||
|
||||
if (itemRet == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (item.template.item_type.equals(engine.Enum.ItemType.GOLD)) {
|
||||
// this is done to prevent the temporary goldItem item
|
||||
// (from the mob) from appearing in player's inventory.
|
||||
// It also updates the goldItem quantity display
|
||||
UpdateGoldMsg updateTargetGold = null;
|
||||
|
||||
if (tar != null)
|
||||
updateTargetGold = new UpdateGoldMsg(tar);
|
||||
else if (corpse != null)
|
||||
updateTargetGold = new UpdateGoldMsg(corpse);
|
||||
|
||||
updateTargetGold.configure();
|
||||
DispatchMessage.dispatchMsgToInterestArea(tar, updateTargetGold, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false);
|
||||
|
||||
UpdateGoldMsg ugm = new UpdateGoldMsg(player);
|
||||
ugm.configure();
|
||||
Dispatch dispatch = Dispatch.borrow(player, ugm);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
|
||||
|
||||
// respond back loot message. Try sending to everyone.
|
||||
|
||||
} else {
|
||||
msg.setSourceType1(0);
|
||||
msg.setSourceType2(0);
|
||||
msg.setSourceID1(0);
|
||||
msg.setSourceID2(0);
|
||||
Dispatch dispatch = Dispatch.borrow(player, msg);
|
||||
//DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY);
|
||||
DispatchMessage.dispatchMsgToInterestArea(tar, msg, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, false, true);
|
||||
LootMsg newItemMsg = new LootMsg(GameObjectType.PlayerCharacter.ordinal(), player.getObjectUUID(), 0, 0, itemRet);
|
||||
dispatch = Dispatch.borrow(player, newItemMsg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY);
|
||||
|
||||
//player.getCharItemManager().updateInventory();
|
||||
}
|
||||
|
||||
//TODO send group loot message if player is grouped and visible
|
||||
Group group = GroupManager.getGroup(player);
|
||||
|
||||
if (group != null && group.getSplitGold() && (item.template.item_type.equals(engine.Enum.ItemType.GOLD) == false)) {
|
||||
String name = item.getName();
|
||||
String text = player.getFirstName() + " has looted " + name + '.';
|
||||
ChatManager.chatGroupInfoCanSee(player, text);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Logger.info(e.getMessage());
|
||||
} finally {
|
||||
item.lootLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// called when player types /show
|
||||
private static void show(ShowMsg msg, ClientConnection origin) throws MsgSendException {
|
||||
|
||||
@@ -642,9 +411,6 @@ public class ClientMessagePump implements NetMsgHandler {
|
||||
case RESETAFTERDEATH:
|
||||
respawn((RespawnMsg) msg, origin);
|
||||
break;
|
||||
case MOVEOBJECTTOCONTAINER:
|
||||
loot((LootMsg) msg, origin);
|
||||
break;
|
||||
case SHOWCOMBATINFO:
|
||||
show((ShowMsg) msg, origin);
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user