Skip to content

Commit

Permalink
Merge pull request #16457 from Treeston/3.3.5-standstatecondition
Browse files Browse the repository at this point in the history
[3.3.5] Add condition for unit sitting/standing
(cherry picked from commit b6720af)
  • Loading branch information
Treeston authored and Shauren committed Apr 8, 2016
1 parent 7c51859 commit 42a01d6
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
41 changes: 40 additions & 1 deletion src/server/game/Conditions/ConditionMgr.cpp
Expand Up @@ -103,7 +103,8 @@ ConditionMgr::ConditionTypeInfo const ConditionMgr::StaticConditionTypeData[COND
{ "Health Pct", true, true, false },
{ "Realm Achievement", true, false, false },
{ "In Water", false, false, false },
{ "Terrain Swap", true, false, false }
{ "Terrain Swap", true, false, false },
{ "Sit/stand state", true, true, false }
};

// Checks if object meets the condition
Expand Down Expand Up @@ -440,6 +441,19 @@ bool Condition::Meets(ConditionSourceInfo& sourceInfo) const
condMeets = object->IsInTerrainSwap(ConditionValue1);
break;
}
case CONDITION_STAND_STATE:
{
if (Unit* unit = object->ToUnit())
{
if (ConditionValue1 == 0)
condMeets = (unit->getStandState() == ConditionValue2);
else if (ConditionValue2 == 0)
condMeets = unit->IsStandState();
else if (ConditionValue2 == 1)
condMeets = unit->IsSitState();
}
break;
}
default:
condMeets = false;
break;
Expand Down Expand Up @@ -618,6 +632,9 @@ uint32 Condition::GetSearcherTypeMaskForCondition() const
case CONDITION_TERRAIN_SWAP:
mask |= GRID_MAP_TYPE_MASK_ALL;
break;
case CONDITION_STAND_STATE:
mask |= GRID_MAP_TYPE_MASK_CREATURE | GRID_MAP_TYPE_MASK_PLAYER;
break;
default:
ASSERT(false && "Condition::GetSearcherTypeMaskForCondition - missing condition handling!");
break;
Expand Down Expand Up @@ -2204,6 +2221,28 @@ bool ConditionMgr::isConditionTypeValid(Condition* cond) const
}
case CONDITION_IN_WATER:
break;
case CONDITION_STAND_STATE:
{
bool valid = false;
switch (cond->ConditionValue1)
{
case 0:
valid = cond->ConditionValue2 <= UNIT_STAND_STATE_SUBMERGED;
break;
case 1:
valid = cond->ConditionValue2 <= 1;
break;
default:
valid = false;
break;
}
if (!valid)
{
TC_LOG_ERROR("sql.sql", "%s has non-existing stand state (%u,%u), skipped.", cond->ToString(true).c_str(), cond->ConditionValue1, cond->ConditionValue2);
return false;
}
break;
}
default:
break;
}
Expand Down
3 changes: 2 additions & 1 deletion src/server/game/Conditions/ConditionMgr.h
Expand Up @@ -90,7 +90,8 @@ enum ConditionTypes
CONDITION_REALM_ACHIEVEMENT = 39, // achievement_id 0 0 true if realm achievement is complete
CONDITION_IN_WATER = 40, // 0 0 0 true if unit in water
CONDITION_TERRAIN_SWAP = 41, // terrainSwap 0 0 true if object is in terrainswap
CONDITION_MAX = 42 // MAX
CONDITION_STAND_STATE = 42, // stateType state 0 true if unit matches specified sitstate (0,x: has exactly state x; 1,0: any standing state; 1,1: any sitting state;)
CONDITION_MAX = 43 // MAX
};

/*! Documentation on implementing a new ConditionSourceType:
Expand Down

0 comments on commit 42a01d6

Please sign in to comment.