Handler created for LootMsg
This commit is contained in:
@@ -32,8 +32,6 @@ import org.pmw.tinylog.Logger;
|
|||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
import static engine.math.FastMath.sqr;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author:
|
* @author:
|
||||||
* @summary: This class is the mainline router for application protocol
|
* @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);
|
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
|
// called when player types /show
|
||||||
private static void show(ShowMsg msg, ClientConnection origin) throws MsgSendException {
|
private static void show(ShowMsg msg, ClientConnection origin) throws MsgSendException {
|
||||||
|
|
||||||
@@ -642,9 +411,6 @@ public class ClientMessagePump implements NetMsgHandler {
|
|||||||
case RESETAFTERDEATH:
|
case RESETAFTERDEATH:
|
||||||
respawn((RespawnMsg) msg, origin);
|
respawn((RespawnMsg) msg, origin);
|
||||||
break;
|
break;
|
||||||
case MOVEOBJECTTOCONTAINER:
|
|
||||||
loot((LootMsg) msg, origin);
|
|
||||||
break;
|
|
||||||
case SHOWCOMBATINFO:
|
case SHOWCOMBATINFO:
|
||||||
show((ShowMsg) msg, origin);
|
show((ShowMsg) msg, origin);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -143,7 +143,7 @@ public enum Protocol {
|
|||||||
MODIFYGUILDSTATE(0x38936FEA, ToggleLfgRecruitingMsg.class, null), //Toggle LFGroup/LFGuild/Recruiting
|
MODIFYGUILDSTATE(0x38936FEA, ToggleLfgRecruitingMsg.class, null), //Toggle LFGroup/LFGuild/Recruiting
|
||||||
MOTD(0xEC841E8D, MOTDMsg.class, MOTDEditHandler.class), //Send/Rec Guild/Nation/IC MOTD Message
|
MOTD(0xEC841E8D, MOTDMsg.class, MOTDEditHandler.class), //Send/Rec Guild/Nation/IC MOTD Message
|
||||||
MOVECORRECTION(0x47FAD1E3, null, null), //Force move to point?
|
MOVECORRECTION(0x47FAD1E3, null, null), //Force move to point?
|
||||||
MOVEOBJECTTOCONTAINER(0xD1639F7C, LootMsg.class, null), //Send/Recv MoveObjectToContainer Msg
|
MOVEOBJECTTOCONTAINER(0xD1639F7C, LootMsg.class, LootMsgHandler.class), //Send/Recv MoveObjectToContainer Msg
|
||||||
MOVETOPOINT(0x49EF7241, MoveToPointMsg.class, MoveToPointHandler.class), // Move to point
|
MOVETOPOINT(0x49EF7241, MoveToPointMsg.class, MoveToPointHandler.class), // Move to point
|
||||||
NAMEVERIFY(0x1B3BF0B1, null, null), // Invalid Name in Character Creation
|
NAMEVERIFY(0x1B3BF0B1, null, null), // Invalid Name in Character Creation
|
||||||
NEWWORLD(0x982E4A77, WorldDataMsg.class, null), // World Data
|
NEWWORLD(0x982E4A77, WorldDataMsg.class, null), // World Data
|
||||||
|
|||||||
@@ -0,0 +1,260 @@
|
|||||||
|
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||||
|
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||||
|
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||||
|
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||||
|
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||||
|
// Magicbane Emulator Project © 2013 - 2022
|
||||||
|
// www.magicbane.com
|
||||||
|
|
||||||
|
package engine.net.client.handlers;
|
||||||
|
|
||||||
|
import engine.Enum;
|
||||||
|
import engine.Enum.DispatchChannel;
|
||||||
|
import engine.exception.MsgSendException;
|
||||||
|
import engine.gameManager.ChatManager;
|
||||||
|
import engine.gameManager.GroupManager;
|
||||||
|
import engine.net.Dispatch;
|
||||||
|
import engine.net.DispatchMessage;
|
||||||
|
import engine.net.client.ClientConnection;
|
||||||
|
import engine.net.client.msg.*;
|
||||||
|
import engine.objects.*;
|
||||||
|
import engine.server.MBServerStatics;
|
||||||
|
import org.pmw.tinylog.Logger;
|
||||||
|
|
||||||
|
import static engine.math.FastMath.sqr;
|
||||||
|
|
||||||
|
public class LootMsgHandler extends AbstractClientMsgHandler {
|
||||||
|
|
||||||
|
public LootMsgHandler() {
|
||||||
|
super(LootMsg.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
|
||||||
|
|
||||||
|
PlayerCharacter player = origin.getPlayerCharacter();
|
||||||
|
|
||||||
|
// Member variable declaration
|
||||||
|
|
||||||
|
LootMsg msg;
|
||||||
|
|
||||||
|
// Member variable assignment
|
||||||
|
|
||||||
|
msg = (LootMsg) baseMsg;
|
||||||
|
|
||||||
|
if (player == null)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (!player.isAlive())
|
||||||
|
return true;
|
||||||
|
|
||||||
|
Item item = msg.getItem();
|
||||||
|
|
||||||
|
if (item == null)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (item.lootLock.tryLock()) {
|
||||||
|
try {
|
||||||
|
Item itemRet = null;
|
||||||
|
// get current owner
|
||||||
|
int targetType = msg.getTargetType();
|
||||||
|
int targetID = msg.getTargetID();
|
||||||
|
|
||||||
|
if (targetType == Enum.GameObjectType.PlayerCharacter.ordinal() || targetType == Enum.GameObjectType.Mob.ordinal() || targetType == Enum.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 true;
|
||||||
|
|
||||||
|
AbstractCharacter tar = null;
|
||||||
|
Corpse corpse = null;
|
||||||
|
|
||||||
|
if (targetType == Enum.GameObjectType.PlayerCharacter.ordinal() || targetType == Enum.GameObjectType.Mob.ordinal()) {
|
||||||
|
|
||||||
|
if (targetType == Enum.GameObjectType.PlayerCharacter.ordinal()) {
|
||||||
|
tar = PlayerCharacter.getFromCache(targetID);
|
||||||
|
|
||||||
|
if (tar == null)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (player.getObjectUUID() != tar.getObjectUUID() && ((PlayerCharacter) tar).isInSafeZone())
|
||||||
|
return true;
|
||||||
|
|
||||||
|
} else if (targetType == Enum.GameObjectType.NPC.ordinal())
|
||||||
|
tar = NPC.getFromCache(targetID);
|
||||||
|
else if (targetType == Enum.GameObjectType.Mob.ordinal())
|
||||||
|
tar = Mob.getFromCache(targetID);
|
||||||
|
|
||||||
|
if (tar == null)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (tar.equals(player)) {
|
||||||
|
ErrorPopupMsg.sendErrorMsg(player, "Cannot loot this item.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//can't loot from someone who is alive.
|
||||||
|
if (AbstractWorldObject.IsAbstractCharacter(tar)) {
|
||||||
|
if (tar.isAlive())
|
||||||
|
return true;
|
||||||
|
// 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() == Enum.GameObjectType.Mob && itemRet != null) {
|
||||||
|
Mob mobTarget = (Mob) tar;
|
||||||
|
|
||||||
|
if (item != null && item.getObjectType() == Enum.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 == Enum.GameObjectType.Corpse.ordinal()) {
|
||||||
|
corpse = Corpse.getCorpse(targetID);
|
||||||
|
|
||||||
|
if (corpse == null)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
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 true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//can't loot other players in safe zone.
|
||||||
|
if (corpse.getBelongsToType() == Enum.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 true;
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
|
||||||
|
//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 true;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (itemRet == null)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
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(Enum.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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user