@ -148,12 +148,6 @@ public class ClientMessagePump implements NetMsgHandler { 
			
		
	
		
		
			
				
					
					            pc . setActive ( true ) ;              pc . setActive ( true ) ;   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					        pc . setLastTarget ( GameObjectType . values ( ) [ msg . getTargetType ( ) ] ,  msg . getTargetID ( ) ) ;          pc . setLastTarget ( GameObjectType . values ( ) [ msg . getTargetType ( ) ] ,  msg . getTargetID ( ) ) ;   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					        if ( ! pc . getTimestamps ( ) . containsKey ( "lastTab" ) )   
			
		
	
		
		
			
				
					
					            pc . getTimestamps ( ) . put ( "lastTab" , System . currentTimeMillis ( ) ) ;   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					        if ( System . currentTimeMillis ( )  -  pc . getTimestamps ( ) . get ( "lastTab" )  <  100 )   
			
		
	
		
		
			
				
					
					            Logger . error ( "USE OF /TAR SUSPECTED BY PLAYER: "  +  pc . getName ( ) ) ;   
			
		
	
		
		
			
				
					
					    }      }   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					    private  static  void  social ( SocialMsg  msg ,  ClientConnection  origin )  throws  MsgSendException  {      private  static  void  social ( SocialMsg  msg ,  ClientConnection  origin )  throws  MsgSendException  {   
			
		
	
	
		
		
			
				
					
						
							
								 
						
						
							
								 
						
						
					 
					@ -1385,33 +1379,24 @@ public class ClientMessagePump implements NetMsgHandler { 
			
		
	
		
		
			
				
					
					    }      }   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					    private  static  void  buyFromNPC ( BuyFromNPCMsg  msg ,  ClientConnection  origin )  {      private  static  void  buyFromNPC ( BuyFromNPCMsg  msg ,  ClientConnection  origin )  {   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					        PlayerCharacter  sourcePlayer  =  SessionManager . getPlayerCharacter ( origin ) ;          PlayerCharacter  sourcePlayer  =  SessionManager . getPlayerCharacter ( origin ) ;   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					        if  ( sourcePlayer  = =  null )          if  ( sourcePlayer  = =  null )   
			
		
	
		
		
			
				
					
					            return ;              return ;   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					        if  ( origin . buyLock . tryLock ( ) )  {          if  ( origin . buyLock . tryLock ( ) )  {   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					            try  {              try  {   
			
		
	
		
		
			
				
					
					                CharacterItemManager  itemMan  =  sourcePlayer . getCharItemManager ( ) ;                  CharacterItemManager  itemMan  =  sourcePlayer . getCharItemManager ( ) ;   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					                if  ( itemMan  = =  null )  {                  if  ( itemMan  = =  null )  {   
			
		
	
		
		
			
				
					
					                    return ;                      return ;   
			
		
	
		
		
			
				
					
					                }                  }   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					                NPC  npc  =  NPC . getFromCache ( msg . getNPCID ( ) ) ;                  NPC  npc  =  NPC . getFromCache ( msg . getNPCID ( ) ) ;   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					                if  ( npc  = =  null )  {                  if  ( npc  = =  null )  {   
			
		
	
		
		
			
				
					
					                    return ;                      return ;   
			
		
	
		
		
			
				
					
					                }                  }   
			
		
	
		
		
			
				
					
					                Item  gold  =  itemMan . getGoldInventory ( ) ;                  Item  gold  =  itemMan . getGoldInventory ( ) ;   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					                if  ( gold  = =  null )  {                  if  ( gold  = =  null )  {   
			
		
	
		
		
			
				
					
					                    return ;                      return ;   
			
		
	
		
		
			
				
					
					                }                  }   
			
		
	
		
		
			
				
					
					                Item  buy  =  null ;                  Item  buy  =  null ;   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					                if  ( msg . getItemType ( )  = =  GameObjectType . MobEquipment . ordinal ( ) )  {                  if  ( msg . getItemType ( )  = =  GameObjectType . MobEquipment . ordinal ( ) )  {   
			
		
	
		
		
			
				
					
					                    ArrayList < MobEquipment >  sellInventory  =  npc . getContract ( ) . getSellInventory ( ) ;                      ArrayList < MobEquipment >  sellInventory  =  npc . getContract ( ) . getSellInventory ( ) ;   
			
		
	
		
		
			
				
					
					                    if  ( sellInventory  = =  null )  {                      if  ( sellInventory  = =  null )  {   
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
						
					 
					@ -1436,30 +1421,19 @@ public class ClientMessagePump implements NetMsgHandler { 
			
		
	
		
		
			
				
					
					                            if ( npc . contractUUID  = =  900  & &  me . getItemBase ( ) . getUUID ( )  = =  1705032 ) {                              if ( npc . contractUUID  = =  900  & &  me . getItemBase ( ) . getUUID ( )  = =  1705032 ) {   
			
		
	
		
		
			
				
					
					                                cost  =  1000000 ;                                  cost  =  1000000 ;   
			
		
	
		
		
			
				
					
					                            }                              }   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					                            float  bargain  =  sourcePlayer . getBargain ( ) ;                              float  bargain  =  sourcePlayer . getBargain ( ) ;   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					                            float  profit  =  npc . getSellPercent ( sourcePlayer )  -  bargain ;                              float  profit  =  npc . getSellPercent ( sourcePlayer )  -  bargain ;   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					                            if ( me . getItemBase ( ) . getType ( ) . equals ( ItemType . POTION ) )                              if ( me . getItemBase ( ) . getType ( ) . equals ( ItemType . POTION ) )   
			
		
	
		
		
			
				
					
					                                profit  - =  1 . 0f ;                                  profit  - =  1 . 0f ;   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					                            if  ( profit  <  1 )                              if  ( profit  <  1 )   
			
		
	
		
		
			
				
					
					                                profit  =  1 ;                                  profit  =  1 ;   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					                            cost  * =  profit ;                              cost  * =  profit ;   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					                            if  ( gold . getNumOfItems ( )  -  cost  <  0 )  {                              if  ( gold . getNumOfItems ( )  -  cost  <  0 )  {   
			
		
	
		
		
			
				
					
					                                //dont' have enough goldItem exit!
                                  //dont' have enough goldItem exit!
   
			
		
	
		
		
			
				
					
					                                // chatMan.chatSystemInfo(pc, "" + "You dont have enough gold.");
                                  // chatMan.chatSystemInfo(pc, "" + "You dont have enough gold.");
   
			
		
	
		
		
			
				
					
					                                return ;                                  return ;   
			
		
	
		
		
			
				
					
					                            }                              }   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					                            Building  b  =  ( ! npc . isStatic ( ) )  ?  npc . getBuilding ( )  :  null ;                              Building  b  =  ( ! npc . isStatic ( ) )  ?  npc . getBuilding ( )  :  null ;   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					                            if  ( b  ! =  null  & &  b . getProtectionState ( ) . equals ( ProtectionState . NPC ) )                              if  ( b  ! =  null  & &  b . getProtectionState ( ) . equals ( ProtectionState . NPC ) )   
			
		
	
		
		
			
				
					
					                                b  =  null ;                                  b  =  null ;   
			
		
	
		
		
			
				
					
					                            int  buildingDeposit  =  cost  -  me . getMagicValue ( ) ;                              int  buildingDeposit  =  cost  -  me . getMagicValue ( ) ;   
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
						
					 
					@ -1467,7 +1441,6 @@ public class ClientMessagePump implements NetMsgHandler { 
			
		
	
		
		
			
				
					
					                                ErrorPopupMsg . sendErrorPopup ( sourcePlayer ,  206 ) ;                                  ErrorPopupMsg . sendErrorPopup ( sourcePlayer ,  206 ) ;   
			
		
	
		
		
			
				
					
					                                return ;                                  return ;   
			
		
	
		
		
			
				
					
					                            }                              }   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					                            if  ( ! itemMan . buyFromNPC ( b ,  cost ,  buildingDeposit ) )  {                              if  ( ! itemMan . buyFromNPC ( b ,  cost ,  buildingDeposit ) )  {   
			
		
	
		
		
			
				
					
					                                // chatMan.chatSystemInfo(pc, "" + "You Failed to buy the item.");
                                  // chatMan.chatSystemInfo(pc, "" + "You Failed to buy the item.");
   
			
		
	
		
		
			
				
					
					                                ChatManager . chatSystemError ( sourcePlayer ,  "Failed To Buy Item" ) ;                                  ChatManager . chatSystemError ( sourcePlayer ,  "Failed To Buy Item" ) ;   
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
						
					 
					@ -1487,7 +1460,7 @@ public class ClientMessagePump implements NetMsgHandler { 
			
		
	
		
		
			
				
					
					                                            item . setNumOfItems ( item . getNumOfItems ( )  +  buystack ) ;                                              item . setNumOfItems ( item . getNumOfItems ( )  +  buystack ) ;   
			
		
	
		
		
			
				
					
					                                            stacked  =  true ;                                              stacked  =  true ;   
			
		
	
		
		
			
				
					
					                                            itemMan . updateInventory ( ) ;                                              itemMan . updateInventory ( ) ;   
			
		
	
		
		
			
				
					
					                                            DbManager . ItemQueries . UPDATE_NUM_ITEMS ( item , item . getNumOfItems ( ) , 0 ) ;                                              DbManager . ItemQueries . UPDATE_NUM_ITEMS ( item , item . getNumOfItems ( ) ) ;   
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					                                            break ;                                              break ;   
			
		
	
		
		
			
				
					
					                                        }                                          }   
			
		
	
		
		
			
				
					
					                                    }                                      }   
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
						
					 
					@ -1498,7 +1471,7 @@ public class ClientMessagePump implements NetMsgHandler { 
			
		
	
		
		
			
				
					
					                                        me . transferEnchants ( buy ) ;                                          me . transferEnchants ( buy ) ;   
			
		
	
		
		
			
				
					
					                                        itemMan . addItemToInventory ( buy ) ;                                          itemMan . addItemToInventory ( buy ) ;   
			
		
	
		
		
			
				
					
					                                        buy . setNumOfItems ( buystack ) ;                                          buy . setNumOfItems ( buystack ) ;   
			
		
	
		
		
			
				
					
					                                        DbManager . ItemQueries . UPDATE_NUM_ITEMS ( buy , buy . getNumOfItems ( ) , 0 ) ;                                          DbManager . ItemQueries . UPDATE_NUM_ITEMS ( buy , buy . getNumOfItems ( ) ) ;   
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					                                    }                                      }   
			
		
	
		
		
			
				
					
					                                }                                  }   
			
		
	
		
		
			
				
					
					                            } else  {                              } else  {   
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
						
					 
					@ -1508,7 +1481,7 @@ public class ClientMessagePump implements NetMsgHandler { 
			
		
	
		
		
			
				
					
					                                    itemMan . addItemToInventory ( buy ) ;                                      itemMan . addItemToInventory ( buy ) ;   
			
		
	
		
		
			
				
					
					                                    if ( npc . contractUUID  = =  900  & &  buy . getItemBaseID ( )  = =  1705032 ) {                                      if ( npc . contractUUID  = =  900  & &  buy . getItemBaseID ( )  = =  1705032 ) {   
			
		
	
		
		
			
				
					
					                                        buy . setNumOfItems ( 10 ) ;                                          buy . setNumOfItems ( 10 ) ;   
			
		
	
		
		
			
				
					
					                                        DbManager . ItemQueries . UPDATE_NUM_ITEMS ( buy , buy . getNumOfItems ( ) , 0 ) ;                                          DbManager . ItemQueries . UPDATE_NUM_ITEMS ( buy , buy . getNumOfItems ( ) ) ;   
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					                                    }                                      }   
			
		
	
		
		
			
				
					
					                                    //itemMan.updateInventory();
                                      //itemMan.updateInventory();
   
			
		
	
		
		
			
				
					
					                                }                                  }   
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
						
					 
					@ -1516,135 +1489,90 @@ public class ClientMessagePump implements NetMsgHandler { 
			
		
	
		
		
			
				
					
					                        }                          }   
			
		
	
		
		
			
				
					
					                    }                      }   
			
		
	
		
		
			
				
					
					                }  else  if  ( msg . getItemType ( )  = =  GameObjectType . Item . ordinal ( ) )  {                  }  else  if  ( msg . getItemType ( )  = =  GameObjectType . Item . ordinal ( ) )  {   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					                    CharacterItemManager  npcCim  =  npc . getCharItemManager ( ) ;                      CharacterItemManager  npcCim  =  npc . getCharItemManager ( ) ;   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					                    if  ( npcCim  = =  null )                      if  ( npcCim  = =  null )   
			
		
	
		
		
			
				
					
					                        return ;                          return ;   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					                    buy  =  Item . getFromCache ( msg . getItemID ( ) ) ;                      buy  =  Item . getFromCache ( msg . getItemID ( ) ) ;   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					                    if  ( buy  = =  null )                      if  ( buy  = =  null )   
			
		
	
		
		
			
				
					
					                        return ;                          return ;   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					                    ItemBase  ib  =  buy . getItemBase ( ) ;                      ItemBase  ib  =  buy . getItemBase ( ) ;   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					                    if  ( ib  = =  null )                      if  ( ib  = =  null )   
			
		
	
		
		
			
				
					
					                        return ;                          return ;   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					                    if  ( ! npcCim . inventoryContains ( buy ) )                      if  ( ! npcCim . inventoryContains ( buy ) )   
			
		
	
		
		
			
				
					
					                        return ;                          return ;   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					                    //test room available for item
                      //test room available for item
   
			
		
	
		
		
			
				
					
					                    if  ( ! itemMan . hasRoomInventory ( ib . getWeight ( ) ) )                      if  ( ! itemMan . hasRoomInventory ( ib . getWeight ( ) ) )   
			
		
	
		
		
			
				
					
					                        return ;                          return ;   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					                    //TODO test cost and subtract goldItem
                      //TODO test cost and subtract goldItem
   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					                    //TODO CHnage this if we ever put NPc city npcs in buildings.
                      //TODO CHnage this if we ever put NPc city npcs in buildings.
   
			
		
	
		
		
			
				
					
					                    int  cost  =  buy . getBaseValue ( ) ;                      int  cost  =  buy . getBaseValue ( ) ;   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					                    if  ( buy . isID ( )  | |  buy . isCustomValue ( ) )                      if  ( buy . isID ( )  | |  buy . isCustomValue ( ) )   
			
		
	
		
		
			
				
					
					                        cost  =  buy . getMagicValue ( ) ;                          cost  =  buy . getMagicValue ( ) ;   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					                    float  bargain  =  sourcePlayer . getBargain ( ) ;                      float  bargain  =  sourcePlayer . getBargain ( ) ;   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					                    float  profit  =  npc . getSellPercent ( sourcePlayer )  -  bargain ;                      float  profit  =  npc . getSellPercent ( sourcePlayer )  -  bargain ;   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					                    if  ( profit  <  1 )                      if  ( profit  <  1 )   
			
		
	
		
		
			
				
					
					                        profit  =  1 ;                          profit  =  1 ;   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					                    if  ( ! buy . isCustomValue ( ) )                      if  ( ! buy . isCustomValue ( ) )   
			
		
	
		
		
			
				
					
					                        cost  * =  profit ;                          cost  * =  profit ;   
			
		
	
		
		
			
				
					
					                    else                      else   
			
		
	
		
		
			
				
					
					                        cost  =  buy . getValue ( ) ;                          cost  =  buy . getValue ( ) ;   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					                    if  ( gold . getNumOfItems ( )  -  cost  <  0 )  {                      if  ( gold . getNumOfItems ( )  -  cost  <  0 )  {   
			
		
	
		
		
			
				
					
					                        ErrorPopupMsg . sendErrorPopup ( sourcePlayer ,  128 ) ;   // Insufficient Gold
                          ErrorPopupMsg . sendErrorPopup ( sourcePlayer ,  128 ) ;   // Insufficient Gold
   
			
		
	
		
		
			
				
					
					                        return ;                          return ;   
			
		
	
		
		
			
				
					
					                    }                      }   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					                    Building  b  =  ( ! npc . isStatic ( ) )  ?  npc . getBuilding ( )  :  null ;                      Building  b  =  ( ! npc . isStatic ( ) )  ?  npc . getBuilding ( )  :  null ;   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					                    if  ( b  ! =  null )                      if  ( b  ! =  null )   
			
		
	
		
		
			
				
					
					                        if  ( b . getProtectionState ( ) . equals ( ProtectionState . NPC ) )                          if  ( b . getProtectionState ( ) . equals ( ProtectionState . NPC ) )   
			
		
	
		
		
			
				
					
					                            b  =  null ;                              b  =  null ;   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					                    int  buildingDeposit  =  cost ;                      int  buildingDeposit  =  cost ;   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					                    if  ( b  ! =  null  & &  ( b . getStrongboxValue ( )  +  buildingDeposit )  >  b . getMaxGold ( )  & &  ! b . isOwnerIsNPC ( ) )  {                      if  ( b  ! =  null  & &  ( b . getStrongboxValue ( )  +  buildingDeposit )  >  b . getMaxGold ( )  & &  ! b . isOwnerIsNPC ( ) )  {   
			
		
	
		
		
			
				
					
					                        ErrorPopupMsg . sendErrorPopup ( sourcePlayer ,  206 ) ;                          ErrorPopupMsg . sendErrorPopup ( sourcePlayer ,  206 ) ;   
			
		
	
		
		
			
				
					
					                        return ;                          return ;   
			
		
	
		
		
			
				
					
					                    }                      }   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					                    if  ( ! itemMan . buyFromNPC ( b ,  cost ,  buildingDeposit ) )  {                      if  ( ! itemMan . buyFromNPC ( b ,  cost ,  buildingDeposit ) )  {   
			
		
	
		
		
			
				
					
					                        ErrorPopupMsg . sendErrorPopup ( sourcePlayer ,  110 ) ;                          ErrorPopupMsg . sendErrorPopup ( sourcePlayer ,  110 ) ;   
			
		
	
		
		
			
				
					
					                        return ;                          return ;   
			
		
	
		
		
			
				
					
					                    }                      }   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					                    if  ( buy  ! =  null )                      if  ( buy  ! =  null )   
			
		
	
		
		
			
				
					
					                        itemMan . buyFromNPC ( buy ,  npc ) ;                          itemMan . buyFromNPC ( buy ,  npc ) ;   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					                }  else  if  ( msg . getItemType ( )  = =  GameObjectType . MobLoot . ordinal ( ) )  {                  }  else  if  ( msg . getItemType ( )  = =  GameObjectType . MobLoot . ordinal ( ) )  {   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					                    CharacterItemManager  npcCim  =  npc . getCharItemManager ( ) ;                      CharacterItemManager  npcCim  =  npc . getCharItemManager ( ) ;   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					                    if  ( npcCim  = =  null )                      if  ( npcCim  = =  null )   
			
		
	
		
		
			
				
					
					                        return ;                          return ;   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					                    buy  =  MobLoot . getFromCache ( msg . getItemID ( ) ) ;                      buy  =  MobLoot . getFromCache ( msg . getItemID ( ) ) ;   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					                    if  ( buy  = =  null )                      if  ( buy  = =  null )   
			
		
	
		
		
			
				
					
					                        return ;                          return ;   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					                    ItemBase  ib  =  buy . getItemBase ( ) ;                      ItemBase  ib  =  buy . getItemBase ( ) ;   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					                    if  ( ib  = =  null )                      if  ( ib  = =  null )   
			
		
	
		
		
			
				
					
					                        return ;                          return ;   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					                    if  ( ! npcCim . inventoryContains ( buy ) )                      if  ( ! npcCim . inventoryContains ( buy ) )   
			
		
	
		
		
			
				
					
					                        return ;                          return ;   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					                    //test room available for item
                      //test room available for item
   
			
		
	
		
		
			
				
					
					                    if  ( ! itemMan . hasRoomInventory ( ib . getWeight ( ) ) )                      if  ( ! itemMan . hasRoomInventory ( ib . getWeight ( ) ) )   
			
		
	
		
		
			
				
					
					                        return ;                          return ;   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					                    //TODO test cost and subtract goldItem
                      //TODO test cost and subtract goldItem
   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					                    //TODO CHnage this if we ever put NPc city npcs in buildings.
                      //TODO CHnage this if we ever put NPc city npcs in buildings.
   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					                    int  cost  =  buy . getMagicValue ( ) ;                      int  cost  =  buy . getMagicValue ( ) ;   
			
		
	
		
		
			
				
					
					                    cost  * =  npc . getSellPercent ( sourcePlayer ) ;                      cost  * =  npc . getSellPercent ( sourcePlayer ) ;   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					                    if  ( gold . getNumOfItems ( )  -  cost  <  0 )  {                      if  ( gold . getNumOfItems ( )  -  cost  <  0 )  {   
			
		
	
		
		
			
				
					
					                        ErrorPopupMsg . sendErrorPopup ( sourcePlayer ,  128 ) ;   // Insufficient Gold
                          ErrorPopupMsg . sendErrorPopup ( sourcePlayer ,  128 ) ;   // Insufficient Gold
   
			
		
	
		
		
			
				
					
					                        return ;                          return ;   
			
		
	
		
		
			
				
					
					                    }                      }   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					                    Building  b  =  ( ! npc . isStatic ( ) )  ?  npc . getBuilding ( )  :  null ;                      Building  b  =  ( ! npc . isStatic ( ) )  ?  npc . getBuilding ( )  :  null ;   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					                    if  ( b  ! =  null  & &  b . getProtectionState ( ) . equals ( ProtectionState . NPC ) )                      if  ( b  ! =  null  & &  b . getProtectionState ( ) . equals ( ProtectionState . NPC ) )   
			
		
	
		
		
			
				
					
					                        b  =  null ;                          b  =  null ;   
			
		
	
		
		
			
				
					
					                    int  buildingDeposit  =  cost ;                      int  buildingDeposit  =  cost ;   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					                    if  ( b  ! =  null  & &  ( b . getStrongboxValue ( )  +  buildingDeposit )  >  b . getMaxGold ( )  & &  ! b . isOwnerIsNPC ( ) )  {                      if  ( b  ! =  null  & &  ( b . getStrongboxValue ( )  +  buildingDeposit )  >  b . getMaxGold ( )  & &  ! b . isOwnerIsNPC ( ) )  {   
			
		
	
		
		
			
				
					
					                        ErrorPopupMsg . sendErrorPopup ( sourcePlayer ,  206 ) ;                          ErrorPopupMsg . sendErrorPopup ( sourcePlayer ,  206 ) ;   
			
		
	
		
		
			
				
					
					                        return ;                          return ;   
			
		
	
		
		
			
				
					
					                    }                      }   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					                    if  ( ! itemMan . buyFromNPC ( b ,  cost ,  buildingDeposit ) )                      if  ( ! itemMan . buyFromNPC ( b ,  cost ,  buildingDeposit ) )   
			
		
	
		
		
			
				
					
					                        return ;                          return ;   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					                    if  ( buy  ! =  null )                      if  ( buy  ! =  null )   
			
		
	
		
		
			
				
					
					                        itemMan . buyFromNPC ( buy ,  npc ) ;                          itemMan . buyFromNPC ( buy ,  npc ) ;   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					                }  else                  }  else   
			
		
	
		
		
			
				
					
					                    return ;                      return ;   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					                if  ( buy  ! =  null )  {                  if  ( buy  ! =  null )  {   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					                    msg . setItem ( buy ) ;                      msg . setItem ( buy ) ;   
			
		
	
		
		
			
				
					
					                    //send the buy message back to update player
                      //send the buy message back to update player
   
			
		
	
		
		
			
				
					
					                    //					msg.setItemType(buy.getObjectType().ordinal());
                      //					msg.setItemType(buy.getObjectType().ordinal());
   
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
						
					 
					@ -1653,14 +1581,12 @@ public class ClientMessagePump implements NetMsgHandler { 
			
		
	
		
		
			
				
					
					                    DispatchMessage . dispatchMsgDispatch ( dispatch ,  DispatchChannel . SECONDARY ) ;                      DispatchMessage . dispatchMsgDispatch ( dispatch ,  DispatchChannel . SECONDARY ) ;   
			
		
	
		
		
			
				
					
					                    itemMan . updateInventory ( ) ;                      itemMan . updateInventory ( ) ;   
			
		
	
		
		
			
				
					
					                }                  }   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					            }  finally  {              }  finally  {   
			
		
	
		
		
			
				
					
					                origin . buyLock . unlock ( ) ;                  origin . buyLock . unlock ( ) ;   
			
		
	
		
		
			
				
					
					            }              }   
			
		
	
		
		
			
				
					
					        }  else  {          }  else  {   
			
		
	
		
		
			
				
					
					            ErrorPopupMsg . sendErrorPopup ( origin . getPlayerCharacter ( ) ,  12 ) ;  // All production slots taken
              ErrorPopupMsg . sendErrorPopup ( origin . getPlayerCharacter ( ) ,  12 ) ;  // All production slots taken
   
			
		
	
		
		
			
				
					
					        }          }   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					    }      }   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					    private  static  void  Repair ( RepairMsg  msg ,  ClientConnection  origin )  {      private  static  void  Repair ( RepairMsg  msg ,  ClientConnection  origin )  {   
			
		
	
	
		
		
			
				
					
						
							
								 
						
						
							
								 
						
						
					 
					@ -1890,9 +1816,6 @@ public class ClientMessagePump implements NetMsgHandler { 
			
		
	
		
		
			
				
					
					        }          }   
			
		
	
		
		
			
				
					
					    }      }   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					    public  static  void  handlePetToggle ( PetMsg  msg ) {   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					    }   
			
		
	
		
		
			
				
					
					    @Override      @Override   
			
		
	
		
		
			
				
					
					    public  boolean  handleClientMsg ( ClientNetMsg  msg )  {      public  boolean  handleClientMsg ( ClientNetMsg  msg )  {   
			
		
	
		
		
			
				
					
					
 
			
		
	
	
		
		
			
				
					
						
							
								 
						
						
							
								 
						
						
					 
					@ -1923,9 +1846,6 @@ public class ClientMessagePump implements NetMsgHandler { 
			
		
	
		
		
			
				
					
					            protocolMsg  =  msg . getProtocolMsg ( ) ;              protocolMsg  =  msg . getProtocolMsg ( ) ;   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					            switch  ( protocolMsg )  {              switch  ( protocolMsg )  {   
			
		
	
		
		
			
				
					
					                case  PET :   
			
		
	
		
		
			
				
					
					                    handlePetToggle ( ( PetMsg ) msg ) ;   
			
		
	
		
		
			
				
					
					                    break ;   
			
		
	
		
		
			
				
					
					                case  SETSELECTEDOBECT :                  case  SETSELECTEDOBECT :   
			
		
	
		
		
			
				
					
					                    ClientMessagePump . targetObject ( ( TargetObjectMsg )  msg ,  origin ) ;                      ClientMessagePump . targetObject ( ( TargetObjectMsg )  msg ,  origin ) ;   
			
		
	
		
		
			
				
					
					                    break ;                      break ;