@ -1,5 +1,6 @@
@@ -1,5 +1,6 @@
package engine.net.client.handlers ;
import engine.Enum ;
import engine.Enum.DispatchChannel ;
import engine.Enum.GameObjectType ;
import engine.Enum.ProfitType ;
@ -36,242 +37,65 @@ public class OrderNPCMsgHandler extends AbstractClientMsgHandler {
@@ -36,242 +37,65 @@ public class OrderNPCMsgHandler extends AbstractClientMsgHandler {
super ( OrderNPCMsg . class ) ;
}
@Override
protected boolean _handleNetMsg ( ClientNetMsg baseMsg , ClientConnection origin ) throws MsgSendException {
// Member variable declarations
public static void processRedeedMob ( Mob mob , Building building , ClientConnection origin ) {
PlayerCharacter player ;
NPC npc ;
Mob mob ;
Building building ;
OrderNPCMsg orderNPCMsg ;
ManageCityAssetsMsg outMsg ;
// Member variable assignment
orderNPCMsg = ( OrderNPCMsg ) baseMsg ;
if ( origin . ordernpcspam > System . currentTimeMillis ( ) )
return true ;
origin . ordernpcspam = System . currentTimeMillis ( ) + 500 ;
Contract contract ;
CharacterItemManager itemMan ;
ItemBase itemBase ;
Item item ;
player = SessionManager . getPlayerCharacter ( origin ) ;
itemMan = player . getCharItemManager ( ) ;
if ( player = = null )
return true ;
contract = mob . getContract ( ) ;
if ( orderNPCMsg . getActionType ( ) = = 28 ) {
OrderNPCMsgHandler . handleCityCommand ( orderNPCMsg , player ) ;
return true ;
if ( ! player . getCharItemManager ( ) . hasRoomInventory ( ( short ) 1 ) ) {
ErrorPopupMsg . sendErrorPopup ( player , 21 ) ;
return ;
}
if ( orderNPCMsg . getObjectType ( ) = = GameObjectType . NPC . ordinal ( ) ) {
npc = NPC . getFromCache ( orderNPCMsg . getNpcUUID ( ) ) ;
if ( npc = = null )
return true ;
building = BuildingManager . getBuildingFromCache ( orderNPCMsg . getBuildingUUID ( ) ) ;
if ( building = = null )
return true ;
if ( building . getHirelings ( ) . containsKey ( npc ) = = false )
return true ;
if ( player . getCharItemManager ( ) . getTradingWith ( ) ! = null ) {
ErrorPopupMsg . sendErrorMsg ( player , "Cannot barter and trade with same timings." ) ;
return true ;
}
player . lastBuildingAccessed = building . getObjectUUID ( ) ;
switch ( orderNPCMsg . getActionType ( ) ) {
case 2 :
player = SessionManager . getPlayerCharacter ( origin ) ;
if ( ManageCityAssetMsgHandler . playerCanManageNotFriends ( player , building ) = = false )
return true ;
if ( building . getHirelings ( ) . containsKey ( npc ) = = false )
return true ;
if ( npc . remove ( ) = = false ) {
PlaceAssetMsg . sendPlaceAssetError ( player . getClientConnection ( ) , 1 , "A Serious error has occurred. Please post details for to ensure transaction integrity" ) ;
return true ;
}
ManageCityAssetsMsg manageCityAssetsMsg = new ManageCityAssetsMsg ( ) ;
manageCityAssetsMsg . actionType = SVR_CLOSE_WINDOW ;
manageCityAssetsMsg . setTargetType ( building . getObjectType ( ) . ordinal ( ) ) ;
manageCityAssetsMsg . setTargetID ( building . getObjectUUID ( ) ) ;
Dispatch dispatch = Dispatch . borrow ( player , manageCityAssetsMsg ) ;
DispatchMessage . dispatchMsgDispatch ( dispatch , DispatchChannel . SECONDARY ) ;
return true ;
case CLIENT_UPGRADE_REQUEST :
if ( BuildingManager . playerCanManage ( player , building ) = = false )
return true ;
processUpgradeNPC ( player , npc ) ;
outMsg = new ManageCityAssetsMsg ( player , building ) ;
// Action TYPE
outMsg . actionType = 3 ;
outMsg . setTargetType ( building . getObjectType ( ) . ordinal ( ) ) ;
outMsg . setTargetID ( building . getObjectUUID ( ) ) ;
outMsg . setTargetType3 ( building . getObjectType ( ) . ordinal ( ) ) ;
outMsg . setTargetID3 ( building . getObjectUUID ( ) ) ;
outMsg . setAssetName1 ( building . getName ( ) ) ;
outMsg . setUnknown54 ( 1 ) ;
dispatch = Dispatch . borrow ( player , outMsg ) ;
DispatchMessage . dispatchMsgDispatch ( dispatch , DispatchChannel . SECONDARY ) ;
break ;
case CLIENT_REDEED_REQUEST :
if ( BuildingManager . PlayerCanControlNotOwner ( building , player ) = = false )
return true ;
processRedeedNPC ( npc , building , origin ) ;
return true ;
//MB TODO HANDLE all profits.
case 7 :
case 8 :
case 9 :
if ( BuildingManager . PlayerCanControlNotOwner ( building , player ) = = false )
return true ;
modifySellProfit ( orderNPCMsg , origin ) ;
dispatch = Dispatch . borrow ( player , orderNPCMsg ) ;
DispatchMessage . dispatchMsgDispatch ( dispatch , DispatchChannel . SECONDARY ) ;
return true ;
case 10 :
case 11 :
case 12 :
if ( BuildingManager . PlayerCanControlNotOwner ( building , player ) = = false )
return true ;
modifyBuyProfit ( orderNPCMsg , origin ) ;
dispatch = Dispatch . borrow ( player , orderNPCMsg ) ;
DispatchMessage . dispatchMsgDispatch ( dispatch , DispatchChannel . SECONDARY ) ;
return true ;
}
// Validation check Owner or IC or friends
if ( BuildingManager . PlayerCanControlNotOwner ( building , player ) = = false )
if ( BuildingManager . playerCanManage ( player , building ) = = false )
return true ;
ManageNPCMsg manageNPCMsg = new ManageNPCMsg ( npc ) ;
Dispatch dispatch = Dispatch . borrow ( player , manageNPCMsg ) ;
DispatchMessage . dispatchMsgDispatch ( dispatch , DispatchChannel . SECONDARY ) ;
return true ;
} else if ( orderNPCMsg . getObjectType ( ) = = GameObjectType . Mob . ordinal ( ) ) {
mob = Mob . getFromCacheDBID ( orderNPCMsg . getNpcUUID ( ) ) ;
if ( mob = = null )
return true ;
building = BuildingManager . getBuildingFromCache ( orderNPCMsg . getBuildingUUID ( ) ) ;
if ( building = = null )
return true ;
if ( ! building . getHirelings ( ) . containsKey ( mob ) )
return true ;
if ( player . getCharItemManager ( ) . getTradingWith ( ) ! = null ) {
ErrorPopupMsg . sendErrorMsg ( player , "Cannot barter and trade with same timings." ) ;
return true ;
}
player . lastBuildingAccessed = building . getObjectUUID ( ) ;
switch ( orderNPCMsg . getActionType ( ) ) {
case 2 :
if ( BuildingManager . playerCanManage ( player , building ) = = false )
return true ;
if ( building . getHirelings ( ) . containsKey ( mob ) = = false )
return true ;
if ( NPCManager . removeMobileFromBuilding ( mob , building ) = = false ) {
PlaceAssetMsg . sendPlaceAssetError ( player . getClientConnection ( ) , 1 , "A Serious error has occurred. Please post details for to ensure transaction integrity" ) ;
return true ;
}
if ( ! building . getHirelings ( ) . containsKey ( mob ) )
return ;
ManageCityAssetsMsg manageCityAssetsMsg = new ManageCityAssetsMsg ( ) ;
manageCityAssetsMsg . actionType = SVR_CLOSE_WINDOW ;
manageCityAssetsMsg . setTargetType ( building . getObjectType ( ) . ordinal ( ) ) ;
manageCityAssetsMsg . setTargetID ( building . getObjectUUID ( ) ) ;
Dispatch dispatch = Dispatch . borrow ( player , manageCityAssetsMsg ) ;
DispatchMessage . dispatchMsgDispatch ( dispatch , DispatchChannel . SECONDARY ) ;
break ;
case 3 :
if ( ! NPCManager . removeMobileFromBuilding ( mob , building ) ) {
PlaceAssetMsg . sendPlaceAssetError ( player . getClientConnection ( ) , 1 , "A Serious error has occurred. Please post details for to ensure transaction integrity" ) ;
return ;
}
if ( BuildingManager . PlayerCanControlNotOwner ( building , player ) = = false )
return true ;
building . getHirelings ( ) . remove ( mob ) ;
processUpgradeNPC ( player , mob ) ;
itemBase = ItemBase . getItemBase ( contract . getContractID ( ) ) ;
outMsg = new ManageCityAssetsMsg ( player , building ) ;
if ( itemBase = = null ) {
Logger . error ( "Could not find Contract for npc: " + mob . getObjectUUID ( ) ) ;
return ;
}
// Action TYPE
outMsg . actionType = 3 ;
outMsg . setTargetType ( building . getObjectType ( ) . ordinal ( ) ) ;
outMsg . setTargetID ( building . getObjectUUID ( ) ) ;
outMsg . setTargetType3 ( building . getObjectType ( ) . ordinal ( ) ) ;
outMsg . setTargetID3 ( building . getObjectUUID ( ) ) ;
outMsg . setAssetName1 ( building . getName ( ) ) ;
outMsg . setUnknown54 ( 1 ) ;
boolean itemWorked = false ;
dispatch = Dispatch . borrow ( player , outMsg ) ;
DispatchMessage . dispatchMsgDispatch ( dispatch , DispatchChannel . SECONDARY ) ;
break ;
case 6 :
item = new Item ( itemBase , player . getObjectUUID ( ) , Enum . OwnerType . PlayerCharacter , ( byte ) ( ( byte ) mob . getRank ( ) - 1 ) , ( byte ) ( ( byte ) mob . getRank ( ) - 1 ) , ( short ) 1 , ( short ) 1 , true , false , Enum . ItemContainerType . INVENTORY , ( byte ) 0 , new ArrayList < > ( ) , "" ) ;
item . setNumOfItems ( 1 ) ;
item . containerType = Enum . ItemContainerType . INVENTORY ;
if ( BuildingManager . PlayerCanControlNotOwner ( building , player ) = = false )
return true ;
try {
item = DbManager . ItemQueries . ADD_ITEM ( item ) ;
itemWorked = true ;
} catch ( Exception e ) {
Logger . error ( e ) ;
}
processRedeedNPC ( mob , building , origin ) ;
return true ;
//MB TODO HANDLE all profits.
case 7 :
case 8 :
case 9 :
break ;
case 10 :
case 11 :
case 12 :
break ;
}
if ( itemWorked ) {
itemMan . addItemToInventory ( item ) ;
itemMan . updateInventory ( ) ;
}
// Validation check Owner or IC
if ( BuildingManager . PlayerCanControlNotOwner ( building , player ) = = false )
if ( BuildingManager . playerCanManage ( player , building ) = = false )
return true ;
ManageCityAssetsMsg mca = new ManageCityAssetsMsg ( ) ;
mca . actionType = NPC . SVR_CLOSE_WINDOW ;
mca . setTargetType ( building . getObjectType ( ) . ordinal ( ) ) ;
mca . setTargetID ( building . getObjectUUID ( ) ) ;
origin . sendMsg ( mca ) ;
ManageNPCMsg manageNPCMsg = new ManageNPCMsg ( mob ) ;
Dispatch dispatch = Dispatch . borrow ( player , manageNPCMsg ) ;
DispatchMessage . dispatchMsgDispatch ( dispatch , DispatchChannel . SECONDARY ) ;
return true ;
}
return true ;
}
private static void modifyBuyProfit ( OrderNPCMsg msg , ClientConnection origin ) {
@ -383,10 +207,10 @@ public class OrderNPCMsgHandler extends AbstractClientMsgHandler {
@@ -383,10 +207,10 @@ public class OrderNPCMsgHandler extends AbstractClientMsgHandler {
if ( orderNpcMsg . getPatrolPoints ( ) ! = null ) {
if ( ! AddPatrolPoints ( building . getObjectUUID ( ) , orderNpcMsg . getPatrolPoints ( ) ) ) {
ErrorPopupMsg . sendErrorMsg ( player , "Patrol Points must be placed on city zone." ) ;
return ;
}
if ( ! AddPatrolPoints ( building . getObjectUUID ( ) , orderNpcMsg . getPatrolPoints ( ) ) ) {
ErrorPopupMsg . sendErrorMsg ( player , "Patrol Points must be placed on city zone." ) ;
return ;
}
for ( AbstractCharacter guard : building . getHirelings ( ) . keySet ( ) ) {
if ( guard . getObjectType ( ) = = GameObjectType . Mob )
@ -466,7 +290,7 @@ public class OrderNPCMsgHandler extends AbstractClientMsgHandler {
@@ -466,7 +290,7 @@ public class OrderNPCMsgHandler extends AbstractClientMsgHandler {
}
}
private synchronized void processRedeedNPC ( AbstractCharacter abstractCharacter , Building building , ClientConnection origin ) {
private static s ynchronized void processRedeedNPC ( AbstractCharacter abstractCharacter , Building building , ClientConnection origin ) {
// Member variable declaration
@ -479,11 +303,11 @@ public class OrderNPCMsgHandler extends AbstractClientMsgHandler {
@@ -479,11 +303,11 @@ public class OrderNPCMsgHandler extends AbstractClientMsgHandler {
if ( cityBuilding = = null )
return ;
npc . processRedeedNPC ( origin ) ;
NPC . processRedeedNPC ( npc , npc . building , origin ) ;
break ;
case Mob :
Mob mob = ( Mob ) abstractCharacter ;
mob . processRedeedMob ( origin ) ;
processRedeedMob ( mob , mob . building , origin ) ;
break ;
}
}
@ -494,36 +318,35 @@ public class OrderNPCMsgHandler extends AbstractClientMsgHandler {
@@ -494,36 +318,35 @@ public class OrderNPCMsgHandler extends AbstractClientMsgHandler {
if ( building = = null )
return false ;
Zone zone = building . getParentZone ( ) ;
if ( zone = = null )
return false ;
return false ;
if ( zone . getPlayerCityUUID ( ) = = 0 )
return false ;
return false ;
City city = building . getCity ( ) ;
if ( city = = null )
return false ;
return false ;
//clear first.
for ( Vector3fImmutable point : patrolPoints ) {
if ( city . isLocationOnCityZone ( point ) = = false ) {
return false ;
}
if ( city . isLocationOnCityZone ( point ) = = false ) {
return false ;
}
}
DbManager . BuildingQueries . CLEAR_PATROL ( buildingID ) ;
for ( Vector3fImmutable point : patrolPoints ) {
if ( ! DbManager . BuildingQueries . ADD_TO_PATROL ( buildingID , point ) )
return false ;
}
@ -573,4 +396,242 @@ public class OrderNPCMsgHandler extends AbstractClientMsgHandler {
@@ -573,4 +396,242 @@ public class OrderNPCMsgHandler extends AbstractClientMsgHandler {
return true ;
}
@Override
protected boolean _handleNetMsg ( ClientNetMsg baseMsg , ClientConnection origin ) throws MsgSendException {
// Member variable declarations
PlayerCharacter player ;
NPC npc ;
Mob mob ;
Building building ;
OrderNPCMsg orderNPCMsg ;
ManageCityAssetsMsg outMsg ;
// Member variable assignment
orderNPCMsg = ( OrderNPCMsg ) baseMsg ;
if ( origin . ordernpcspam > System . currentTimeMillis ( ) )
return true ;
origin . ordernpcspam = System . currentTimeMillis ( ) + 500 ;
player = SessionManager . getPlayerCharacter ( origin ) ;
if ( player = = null )
return true ;
if ( orderNPCMsg . getActionType ( ) = = 28 ) {
OrderNPCMsgHandler . handleCityCommand ( orderNPCMsg , player ) ;
return true ;
}
if ( orderNPCMsg . getObjectType ( ) = = GameObjectType . NPC . ordinal ( ) ) {
npc = NPC . getFromCache ( orderNPCMsg . getNpcUUID ( ) ) ;
if ( npc = = null )
return true ;
building = BuildingManager . getBuildingFromCache ( orderNPCMsg . getBuildingUUID ( ) ) ;
if ( building = = null )
return true ;
if ( building . getHirelings ( ) . containsKey ( npc ) = = false )
return true ;
if ( player . getCharItemManager ( ) . getTradingWith ( ) ! = null ) {
ErrorPopupMsg . sendErrorMsg ( player , "Cannot barter and trade with same timings." ) ;
return true ;
}
player . lastBuildingAccessed = building . getObjectUUID ( ) ;
switch ( orderNPCMsg . getActionType ( ) ) {
case 2 :
player = SessionManager . getPlayerCharacter ( origin ) ;
if ( ManageCityAssetMsgHandler . playerCanManageNotFriends ( player , building ) = = false )
return true ;
if ( building . getHirelings ( ) . containsKey ( npc ) = = false )
return true ;
if ( npc . remove ( ) = = false ) {
PlaceAssetMsg . sendPlaceAssetError ( player . getClientConnection ( ) , 1 , "A Serious error has occurred. Please post details for to ensure transaction integrity" ) ;
return true ;
}
ManageCityAssetsMsg manageCityAssetsMsg = new ManageCityAssetsMsg ( ) ;
manageCityAssetsMsg . actionType = SVR_CLOSE_WINDOW ;
manageCityAssetsMsg . setTargetType ( building . getObjectType ( ) . ordinal ( ) ) ;
manageCityAssetsMsg . setTargetID ( building . getObjectUUID ( ) ) ;
Dispatch dispatch = Dispatch . borrow ( player , manageCityAssetsMsg ) ;
DispatchMessage . dispatchMsgDispatch ( dispatch , DispatchChannel . SECONDARY ) ;
return true ;
case CLIENT_UPGRADE_REQUEST :
if ( BuildingManager . playerCanManage ( player , building ) = = false )
return true ;
processUpgradeNPC ( player , npc ) ;
outMsg = new ManageCityAssetsMsg ( player , building ) ;
// Action TYPE
outMsg . actionType = 3 ;
outMsg . setTargetType ( building . getObjectType ( ) . ordinal ( ) ) ;
outMsg . setTargetID ( building . getObjectUUID ( ) ) ;
outMsg . setTargetType3 ( building . getObjectType ( ) . ordinal ( ) ) ;
outMsg . setTargetID3 ( building . getObjectUUID ( ) ) ;
outMsg . setAssetName1 ( building . getName ( ) ) ;
outMsg . setUnknown54 ( 1 ) ;
dispatch = Dispatch . borrow ( player , outMsg ) ;
DispatchMessage . dispatchMsgDispatch ( dispatch , DispatchChannel . SECONDARY ) ;
break ;
case CLIENT_REDEED_REQUEST :
if ( BuildingManager . PlayerCanControlNotOwner ( building , player ) = = false )
return true ;
processRedeedNPC ( npc , building , origin ) ;
return true ;
//MB TODO HANDLE all profits.
case 7 :
case 8 :
case 9 :
if ( BuildingManager . PlayerCanControlNotOwner ( building , player ) = = false )
return true ;
modifySellProfit ( orderNPCMsg , origin ) ;
dispatch = Dispatch . borrow ( player , orderNPCMsg ) ;
DispatchMessage . dispatchMsgDispatch ( dispatch , DispatchChannel . SECONDARY ) ;
return true ;
case 10 :
case 11 :
case 12 :
if ( BuildingManager . PlayerCanControlNotOwner ( building , player ) = = false )
return true ;
modifyBuyProfit ( orderNPCMsg , origin ) ;
dispatch = Dispatch . borrow ( player , orderNPCMsg ) ;
DispatchMessage . dispatchMsgDispatch ( dispatch , DispatchChannel . SECONDARY ) ;
return true ;
}
// Validation check Owner or IC or friends
if ( BuildingManager . PlayerCanControlNotOwner ( building , player ) = = false )
if ( BuildingManager . playerCanManage ( player , building ) = = false )
return true ;
ManageNPCMsg manageNPCMsg = new ManageNPCMsg ( npc ) ;
Dispatch dispatch = Dispatch . borrow ( player , manageNPCMsg ) ;
DispatchMessage . dispatchMsgDispatch ( dispatch , DispatchChannel . SECONDARY ) ;
return true ;
} else if ( orderNPCMsg . getObjectType ( ) = = GameObjectType . Mob . ordinal ( ) ) {
mob = Mob . getFromCacheDBID ( orderNPCMsg . getNpcUUID ( ) ) ;
if ( mob = = null )
return true ;
building = BuildingManager . getBuildingFromCache ( orderNPCMsg . getBuildingUUID ( ) ) ;
if ( building = = null )
return true ;
if ( ! building . getHirelings ( ) . containsKey ( mob ) )
return true ;
if ( player . getCharItemManager ( ) . getTradingWith ( ) ! = null ) {
ErrorPopupMsg . sendErrorMsg ( player , "Cannot barter and trade with same timings." ) ;
return true ;
}
player . lastBuildingAccessed = building . getObjectUUID ( ) ;
switch ( orderNPCMsg . getActionType ( ) ) {
case 2 :
if ( BuildingManager . playerCanManage ( player , building ) = = false )
return true ;
if ( building . getHirelings ( ) . containsKey ( mob ) = = false )
return true ;
if ( NPCManager . removeMobileFromBuilding ( mob , building ) = = false ) {
PlaceAssetMsg . sendPlaceAssetError ( player . getClientConnection ( ) , 1 , "A Serious error has occurred. Please post details for to ensure transaction integrity" ) ;
return true ;
}
ManageCityAssetsMsg manageCityAssetsMsg = new ManageCityAssetsMsg ( ) ;
manageCityAssetsMsg . actionType = SVR_CLOSE_WINDOW ;
manageCityAssetsMsg . setTargetType ( building . getObjectType ( ) . ordinal ( ) ) ;
manageCityAssetsMsg . setTargetID ( building . getObjectUUID ( ) ) ;
Dispatch dispatch = Dispatch . borrow ( player , manageCityAssetsMsg ) ;
DispatchMessage . dispatchMsgDispatch ( dispatch , DispatchChannel . SECONDARY ) ;
break ;
case 3 :
if ( BuildingManager . PlayerCanControlNotOwner ( building , player ) = = false )
return true ;
processUpgradeNPC ( player , mob ) ;
outMsg = new ManageCityAssetsMsg ( player , building ) ;
// Action TYPE
outMsg . actionType = 3 ;
outMsg . setTargetType ( building . getObjectType ( ) . ordinal ( ) ) ;
outMsg . setTargetID ( building . getObjectUUID ( ) ) ;
outMsg . setTargetType3 ( building . getObjectType ( ) . ordinal ( ) ) ;
outMsg . setTargetID3 ( building . getObjectUUID ( ) ) ;
outMsg . setAssetName1 ( building . getName ( ) ) ;
outMsg . setUnknown54 ( 1 ) ;
dispatch = Dispatch . borrow ( player , outMsg ) ;
DispatchMessage . dispatchMsgDispatch ( dispatch , DispatchChannel . SECONDARY ) ;
break ;
case 6 :
if ( BuildingManager . PlayerCanControlNotOwner ( building , player ) = = false )
return true ;
processRedeedNPC ( mob , building , origin ) ;
return true ;
//MB TODO HANDLE all profits.
case 7 :
case 8 :
case 9 :
break ;
case 10 :
case 11 :
case 12 :
break ;
}
// Validation check Owner or IC
if ( BuildingManager . PlayerCanControlNotOwner ( building , player ) = = false )
if ( BuildingManager . playerCanManage ( player , building ) = = false )
return true ;
ManageNPCMsg manageNPCMsg = new ManageNPCMsg ( mob ) ;
Dispatch dispatch = Dispatch . borrow ( player , manageNPCMsg ) ;
DispatchMessage . dispatchMsgDispatch ( dispatch , DispatchChannel . SECONDARY ) ;
return true ;
}
return true ;
}
}