D2BS
Public Member Functions | Public Attributes

Unit Class Reference

This class represents a unit (monster, wp, npc, character, etc) in the game. More...

List of all members.

Public Member Functions

bool getNext ()
 Get the next unit that matches the originally given name or class id and originally specified mode.
bool getNext (String szName)
 Get the next unit that matches the given name and originally specified mode.
bool getNext (uint32_t dwClassId)
 Get the next unit that matches the given class id and originally specified mode.
bool getNext (String szName, uint32_t dwMode)
 Get the next unit that matches the given name and mode.
bool getNext (uint32_t dwClassId, uint32_t dwMode)
 Get the next unit that matches the given class id and mode.
void cancel ()
 Cancel whatever's going on.
bool repair ()
 Try to repair.
bool useMenu (int menuItem)
 Use an NPC menu.
bool interact ()
 Interact with the unit.
bool interact (int destId)
 Interact with a waypoint.
Unit getItem (String name, uint32_t mode=(uint32_t)-1, uint32_t nUnitId=(uint32_t)-1)
 Get an item from inventory by name, mode and nUnitId.
Unit getItem (uint32_t classId=(uint32_t)-1, uint32_t mode=(uint32_t)-1, uint32_t nUnitId=(uint32_t)-1)
 Get an item from inventory by classId, mode and nUnitId.
Unit[] getItems ()
 Get all items from inventory.
bool getMerc (bool dummy)
 Get whether this player has a merc.
Unit getMerc ()
 Get a player's merc.
String getSkill (int hand)
 Get skill name from hand.
int getSkill (int hand)
 Get skill id from hand.
int[][] getSkill (int dummy)
 Get all skills.
int getSkill (int nSkillId, int nExt)
 Calls D2COMMON_GetSkillLevel and returns the result.
Unit getParent ()
 Gets the parent of a unit.
String getParent ()
 Gets the parent of a unit.
void overhead (Object message)
 Puts the string equivalent of message over the unit.
int getFlags ()
 Returns the item flags.
bool getFlag (int flags)
 Same as getFlags, but returns a boolean.
double getStat (int nStat, int nSubIndex=0)
 Get a stat by stat id and sub index.
int getStat (int nStat, int nSubIndex=0)
 Get a stat by stat id and sub index.
int[][] getStat (int nStat, int nSubIndex=0)
 Get an array of all the stats of the item.
bool getState (int nState)
 Return whether or not the unit has a given state.
int getPrice (Unit npc, int buysell=0)
 Get the price of the item at a given npc, with choice of buying or selling, in the current difficulty.
int getPrice (int npcId=148, int buysell=0)
 Get the price of the item at a given npc (by id), which choice of buying or selling, in the current difficulty.
int getPrice (Unit npc, int buysell, int difficulty)
 Get the price of the item at a given npc, with choice of buying or selling, in a given difficulty.
int getPrice (int npcId, int buysell, int difficulty)
 Get the price of the item at a given npc (by id), with choice of buying or selling, in a given difficulty.
bool getEnchant (int nEnchant)
 Determine whether or not a unit has a given enchant.
bool shop (int dwMode)
 Shop with a given npc, either buying or selling.
bool setSkill (String skillName, int nHand)
 Set the skill on the given hand to be skill with name skillName.
bool setSkill (int nSkillId, int nHand)
 Set the skill on the given hand to be skill with id nSkillId.
void move (int x, int y)
 Move to the given location.
void move ()
 Move to this unit.
int getQuest (int nAct, int nQuest)
 Get the quest flag for a quest specified by act and quest number.
int getMinionCount (int nType)
 Get the number of minions of a certain type.
int getRepairCost (int nNpcClassId=154)
 Get price to repair this unit at the current npc given by nNpcClassId.
int getItemCost (int nMode, int nNpcClassId=154)
 Get the cost to do something (buy, sell, repair) with the given item, at the given npc.
int getItemCost (int nMode, int nNpcClassId, int nDifficulty)
 Get the cost to do something (buy, sell, repair) with the given item, at the given npc, in the given difficulty.
int getItemCost (int nMode, Unit npc, int nDifficulty)
 Get the cost to do something (buy, sell, repair) with the given item, at the given npc, in the given difficulty.
int getItemCost (int nMode, Unit npc)
 Get the cost to do something (buy, sell, repair) with the given item, at the given npc.

Public Attributes

int type
 The type of the unit.
int classid
 The class id of the object.
int mode
 The mode of the unit.
String name
 The name of the unit.
int act
 The act where the unit is currently located.
int gid
 The unit unique id.
int x
 The x location of the unit.
int y
 The y location of the unit.
int targetx
 The target x location of the unit.
int targety
 The target y location of the unit.
int area
 The id of the area (level) the unit is located in.
int hp
 The unit's current health.
int hpmax
 The unit's maximum health.
int mp
 The unit's current mana.
int mpmax
 The unit's maximum mana.
int stamina
 The unit's current stamina.
int staminamax
 The unit's maximum stamina.
int charlvl
 The character level.
int itemcount
 The number of items in inventory.
int owner
 The unit id of the owner of the unit.
int ownertype
 The type of owner.
int spectype
 The special type of the unit.
int direction
 The direction of the unit.
int uniqueid
 The unique id of a boss.
String code
 The three digit code for an item.
String prefix
 The magic prefix of the item.
String suffix
 The magic suffix of the item.
String[] prefixes
 The magic prefixes of the item.
String[] suffixes
 The magic suffixes of the item.
int prefixnum
 The id code for the magic prefix.
int suffixnum
 The id code for the magic suffix.
int[] prefixnums
 The id codes for the magic prefixes.
int[] suffixnums
 The id codes for the magic suffixes.
String fname
 The full name of an item.
int quality
 The item quality.
int node
 No clue.
int location
 The location of the item (ground, inventory, stash, etc.).
int sizex
 The x size of the item.
int sizey
 The y size of the item.
int itemType
 The type of the item.
String description
 The description of the item.
int bodylocation
 The equipped location of the item.
int ilvl
 Item level.
int lvlreq
 Level requirement (character level required to use the item).
int gfx
 Get the id for the graphic used for the item.
int runwalk
 Whether the controlled character is in the always run mode or not.
int weaponswitch
 Set the weapon switch.
int objtype
 The object type.
int islocked
 Whether or not the chest is locked.

Detailed Description

This class represents a unit (monster, wp, npc, character, etc) in the game.


Member Function Documentation

void Unit::cancel ( )

Cancel whatever's going on.

If there's scrolling text clear it. If you're interacting to an NPC, stop. If there's an item on the cursor, drop it. Otherwise close any other interaction that might be going on.

bool Unit::getEnchant ( int  nEnchant)

Determine whether or not a unit has a given enchant.

Parameters:
nEnchantEnchantment id.
Returns:
Whether or not the unit has the enchantment.
bool Unit::getFlag ( int  flags)

Same as getFlags, but returns a boolean.

Returns true if any of the flags given match the item flags.

getFlags

Parameters:
flagsFlags to check.
Returns:
true if any of the flags are set in the item flags.
int Unit::getFlags ( )

Returns the item flags.

Returns:
Item flags:

0x00000001 - Equipped

0x00000008 - In socket

0x00000010 - Identified

0x00000040 - Weapon/shield is in the active weapon switch

0x00000080 - Weapon/shield is in the inactive weapon switch

0x00000100 - Item is broken

0x00000400 - Full rejuv

0x00000800 - Socketed

0x00002000 - In the trade or gamble screen

0x00004000 - Not in a socket

0x00010000 - Is an ear

0x00020000 - A starting item (worth only 1 gold)

0x00200000 - Rune, or potion, or mephisto's soulstone

0x00400000 - Ethereal

0x00800000 - Is an item

0x01000000 - Personalized

0x04000000 - Runeword

Source: http://subversion.assembla.com/svn/d2bs/scripts/YAMB/libs/YAMB/common/YAM-Common.dbl r1086

Unit Unit::getItem ( String  name,
uint32_t  mode = (uint32_t)-1,
uint32_t  nUnitId = (uint32_t)-1 
)

Get an item from inventory by name, mode and nUnitId.

Parameters:
nameThe name of the unit to look for.
modeEither the mode being searched for, or a bitmask with bit 29 set and bits 0-28 corresponding to modes of units being searched for.
nUnitIdThe unique id of the unit.
Returns:
The first item found that matches the description.
Unit Unit::getItem ( uint32_t  classId = (uint32_t)-1,
uint32_t  mode = (uint32_t)-1,
uint32_t  nUnitId = (uint32_t)-1 
)

Get an item from inventory by classId, mode and nUnitId.

Parameters:
classIdThe class id of the unit.
modeEither the mode being searched for, or a bitmask with bit 29 set and bits 0-28 corresponding to modes of units being searched for.
nUnitIdThe unique id of the unit.
Returns:
The first item found that matches the description.
int Unit::getItemCost ( int  nMode,
int  nNpcClassId = 154 
)

Get the cost to do something (buy, sell, repair) with the given item, at the given npc.

Parameters:
nModeWhat to do: 0 - buy, 1 - sell, 2 - repair.
nNpcClassIdThe class id of the npc to check the price with.
Returns:
The price.
int Unit::getItemCost ( int  nMode,
int  nNpcClassId,
int  nDifficulty 
)

Get the cost to do something (buy, sell, repair) with the given item, at the given npc, in the given difficulty.

Parameters:
nModeWhat to do: 0 - buy, 1 - sell, 2 - repair.
nNpcClassIdThe class id of the npc to check the price with.
nDifficultyThe difficulty to check the price in.
Returns:
The price.
int Unit::getItemCost ( int  nMode,
Unit  npc,
int  nDifficulty 
)

Get the cost to do something (buy, sell, repair) with the given item, at the given npc, in the given difficulty.

Parameters:
nModeWhat to do: 0 - buy, 1 - sell, 2 - repair.
npcThe npc to check the price with.
nDifficultyThe difficulty to check the price in.
Returns:
The price.
int Unit::getItemCost ( int  nMode,
Unit  npc 
)

Get the cost to do something (buy, sell, repair) with the given item, at the given npc.

Parameters:
nModeWhat to do: 0 - buy, 1 - sell, 2 - repair.
npcThe npc to check the price with.
Returns:
The price.
Unit [] Unit::getItems ( )

Get all items from inventory.

Returns:
An array of all the items from inventory.
bool Unit::getMerc ( bool  dummy)

Get whether this player has a merc.

The unit being operated on should be a player.

Parameters:
dummyUsed to signify boolean result instead of object. Should be true.
Returns:
true if the player has a live merc.
Unit Unit::getMerc ( )

Get a player's merc.

The unit being operated on should be a player.

Returns:
The merc if there is one.
int Unit::getMinionCount ( int  nType)

Get the number of minions of a certain type.

Parameters:
nTypeThe type of the minions.
Returns:
The number of minions of the specified type.
bool Unit::getNext ( String  szName)

Get the next unit that matches the given name and originally specified mode.

Parameters:
szNameThe name to look for.
Returns:
Whether another unit was found.
bool Unit::getNext ( String  szName,
uint32_t  dwMode 
)

Get the next unit that matches the given name and mode.

Parameters:
szNameThe name to look for.
dwModeEither the mode being searched for, or a bitmask with bit 29 set and bits 0-28 corresponding to modes of units being searched for.
Returns:
Whether another unit was found.
bool Unit::getNext ( uint32_t  dwClassId,
uint32_t  dwMode 
)

Get the next unit that matches the given class id and mode.

Parameters:
dwClassIdThe class id to look for.
dwModeEither the mode being searched for, or a bitmask with bit 29 set and bits 0-28 corresponding to modes of units being searched for.
Returns:
Whether another unit was found.
bool Unit::getNext ( uint32_t  dwClassId)

Get the next unit that matches the given class id and originally specified mode.

Parameters:
dwClassIdThe class id to look for.
Returns:
Whether another unit was found.
bool Unit::getNext ( )

Get the next unit that matches the originally given name or class id and originally specified mode.

Returns:
Whether another unit was found.
Unit Unit::getParent ( )

Gets the parent of a unit.

This function is used for monster and item units.

Returns:
The parent unit.
String Unit::getParent ( )

Gets the parent of a unit.

This function is used for object units.

Returns:
The parent's name.
int Unit::getPrice ( int  npcId,
int  buysell,
int  difficulty 
)

Get the price of the item at a given npc (by id), with choice of buying or selling, in a given difficulty.

Todo:
Determine the meaning of "buysell".
Parameters:
npcIdThe id of the npc to determine the price at.
buysellUnknown
difficultyThe difficulty of interest: 0 - normal, 1 - nightmare, 2 - hell
Returns:
The price requested.
int Unit::getPrice ( Unit  npc,
int  buysell,
int  difficulty 
)

Get the price of the item at a given npc, with choice of buying or selling, in a given difficulty.

Todo:
Determine the meaning of "buysell".
Parameters:
npcThe npc to determine the price at.
buysellUnknown
difficultyThe difficulty of interest: 0 - normal, 1 - nightmare, 2 - hell
Returns:
The price requested.
int Unit::getPrice ( Unit  npc,
int  buysell = 0 
)

Get the price of the item at a given npc, with choice of buying or selling, in the current difficulty.

Todo:
Determine the meaning of "buysell".
Parameters:
npcThe npc to determine the price at.
buysellUnknown
Returns:
The price requested.
int Unit::getPrice ( int  npcId = 148,
int  buysell = 0 
)

Get the price of the item at a given npc (by id), which choice of buying or selling, in the current difficulty.

Todo:
Determine the meaning of "buysell".
Parameters:
npcIdThe id of the npc to determine the price at.
buysellUnknown
Returns:
The price requested.
int Unit::getQuest ( int  nAct,
int  nQuest 
)

Get the quest flag for a quest specified by act and quest number.

Parameters:
nActThe act of the quest.
nQuestThe quest number.
Returns:
The quest flag for the specified quest.
int Unit::getRepairCost ( int  nNpcClassId = 154)

Get price to repair this unit at the current npc given by nNpcClassId.

Parameters:
nNpcClassIdThe class id of the npc to get the price for repair at.
Returns:
The price to repair the given unit.
String Unit::getSkill ( int  hand)

Get skill name from hand.

Parameters:
handHand to get the skill name off.

0 - Right hand

1 - Left hand

Returns:
Skill name.
int Unit::getSkill ( int  hand)

Get skill id from hand.

Parameters:
handHand to get the skill id off.

2 - Right hand

3 - Left hand

Returns:
Skill id.
int [][] Unit::getSkill ( int  dummy)

Get all skills.

Gets all skill ids, along with corresponding base and total skill levels.

Parameters:
dummyShould be 4.
Returns:
An array of arrays of integers. Inside the inner array the 0th index is the skill id, the 1st index is the base skill level and the 2nd index is the total skill level. Only the first 256 skills are read.
int Unit::getSkill ( int  nSkillId,
int  nExt 
)

Calls D2COMMON_GetSkillLevel and returns the result.

Todo:
Figure out what D2COMMON_GetSkillLevel does.
Returns:
Whatever D2COMMON_GetSkillLevel returns.
int [][] Unit::getStat ( int  nStat,
int  nSubIndex = 0 
)

Get an array of all the stats of the item.

Parameters:
nStatSet to -1.
nSubIndexIgnored.
Returns:
An array of the first 64 stats. The indices of the inner array are: 0 - nStat, 1 - nSubIndex, 2 - nValue.
double Unit::getStat ( int  nStat,
int  nSubIndex = 0 
)

Get a stat by stat id and sub index.

Used for stat 13.

Parameters:
nStatThe stat type. See http://forums.d2botnet.org/viewtopic.php?f=18&t=989
nSubIndexA subindex to a certain type of stat. For instance a specific skill for the +1 to skill tab stat.
Returns:
The stat value.
int Unit::getStat ( int  nStat,
int  nSubIndex = 0 
)

Get a stat by stat id and sub index.

Used for everything except stat 13.

Parameters:
nStatThe stat type. See http://forums.d2botnet.org/viewtopic.php?f=18&t=989
nSubIndexA subindex to a certain type of stat. For instance a specific skill for the +1 to skill tab stat.
Returns:
The stat value.
bool Unit::getState ( int  nState)

Return whether or not the unit has a given state.

Parameters:
nStateThe state id.
Returns:
Whether or not the unit has the state.
bool Unit::interact ( )

Interact with the unit.

If the unit is an item in inventory or stash pick it up. Otherwise click it on the map.

bool Unit::interact ( int  destId)

Interact with a waypoint.

If the unit is an object, assume it's a waypoint, and take it.

Parameters:
destIdThe area id of the destination to select.
void Unit::move ( int  x,
int  y 
)

Move to the given location.

Parameters:
xThe x location.
yThe y location.
bool Unit::repair ( )

Try to repair.

Need to be able to find unit that you're trying to repair with. That means the unit needs to still be in the server unit hash table.

Returns:
true if successful.
bool Unit::setSkill ( int  nSkillId,
int  nHand 
)

Set the skill on the given hand to be skill with id nSkillId.

Waits up to one second for the skill to be set.

Todo:
Fix argc < 1, should be argc < 2
Parameters:
nSkillIdId of the skill to put up.
nHandHand to put the skill on. non-zero left, 0 - right.
Returns:
Whether operation was successful.
bool Unit::setSkill ( String  skillName,
int  nHand 
)

Set the skill on the given hand to be skill with name skillName.

Waits up to one second for the skill to be set.

Todo:
Fix argc < 1, should be argc < 2
Parameters:
skillNameName of the skill to put up.
nHandHand to put the skill on. non-zero left, 0 - right.
Returns:
Whether operation was successful.
bool Unit::shop ( int  dwMode)

Shop with a given npc, either buying or selling.

Parameters:
dwModeWhat to do with the item. 1 - Sell, 2 - Buy, 6 - ?
Returns:
Whether or not the shop went through.
bool Unit::useMenu ( int  menuItem)

Use an NPC menu.

Need to be able to find unit that you're trying to repair with. That means the unit needs to still be in the server unit hash table.

Parameters:
menuItemIndex of the menu item to click.
Returns:
true if menu was found.

Member Data Documentation

The id of the area (level) the unit is located in.

Todo:
Get a reference for the area IDs.

The equipped location of the item.

0 - Not equipped

1 - Helmet

2 - Amulet

3 - Armor

4 - Right hand slot 1

5 - Left hand slot 1

6 - Right ring

7 - Left ring

8 - Belt

9 - Boots

10 - Gloves

11 - Right hand slot 2

12 - Left hand slot 2

The character level.

The level that determines stat points, skill levels, etc.

String Unit::code

The three digit code for an item.

See: http://forums.d2botnet.org/viewtopic.php?f=18&t=991

The direction of the unit.

Todo:
Figure out what the direction is.

The unit unique id.

Referred to simply as the unit id. Used along with the unit type to uniquely identify the unit.

Item level.

Used for things like item stat rolling.

The type of the item.

Todo:
Put together a reference for item type.

The location of the item (ground, inventory, stash, etc.).

0 - Ground

1 - Equipped

2 - Belt

3 - Inventory

4 - Store

5 - Trade

6 - Cube

7 - Stash

Source: d2botnet code

No clue.

Todo:
Get a clue.

The object type.

Todo:
Figure out what this means.

The type of owner.

type

The item quality.

1 - Low quality

2 - Normal

3 - Superior

4 - Magic

5 - Set

6 - Rare

7 - Unique

8 - Crafted

Source: botNET

Whether the controlled character is in the always run mode or not.

0 - Walk unless directed to run 1 - Always run

The special type of the unit.

Represents things like unique, minion, boss, etc.

1 - "Normal" Boss 2 - Champion 4 - Boss 8 - Minion

The target x location of the unit.

Where the game is taking the unit.

The target y location of the unit.

Where the game is taking the unit.

The type of the unit.

0 - Player

1 - NPC

2 - Object

3 - Missile

4 - Item

5 - Warp

Source: botNET

The unique id of a boss.

Taken from pUnit->pMonsterData->wUniqueNo. Not the same thing as the gid (unit id).