diff options
| author | Shauren <shauren.trinity@gmail.com> | 2015-10-25 00:22:21 +0200 | 
|---|---|---|
| committer | Shauren <shauren.trinity@gmail.com> | 2015-10-25 00:22:21 +0200 | 
| commit | 52d5de1a7f980193d0d2598f86596cca2dad0de4 (patch) | |
| tree | 644d1d250119f7646bc1adc3bba367201dbd4616 /src/server/game/Conditions/ConditionMgr.cpp | |
| parent | 51e1d28668cc893089ceb3fa6f5aa2a045af560f (diff) | |
Core/Conditions: Phase condtion changes
* SourceGroup defines which phase should the condition affect
* SourceEntry limits the area of the phase (alternatively 0 means all areas)
Diffstat (limited to 'src/server/game/Conditions/ConditionMgr.cpp')
| -rw-r--r-- | src/server/game/Conditions/ConditionMgr.cpp | 105 | 
1 files changed, 102 insertions, 3 deletions
diff --git a/src/server/game/Conditions/ConditionMgr.cpp b/src/server/game/Conditions/ConditionMgr.cpp index dd3f3244f5b..42511736154 100644 --- a/src/server/game/Conditions/ConditionMgr.cpp +++ b/src/server/game/Conditions/ConditionMgr.cpp @@ -814,7 +814,8 @@ bool ConditionMgr::CanHaveSourceGroupSet(ConditionSourceType sourceType)              sourceType == CONDITION_SOURCE_TYPE_SPELL_IMPLICIT_TARGET ||              sourceType == CONDITION_SOURCE_TYPE_SPELL_CLICK_EVENT ||              sourceType == CONDITION_SOURCE_TYPE_SMART_EVENT || -            sourceType == CONDITION_SOURCE_TYPE_NPC_VENDOR); +            sourceType == CONDITION_SOURCE_TYPE_NPC_VENDOR || +            sourceType == CONDITION_SOURCE_TYPE_PHASE);  }  bool ConditionMgr::CanHaveSourceIdSet(ConditionSourceType sourceType) @@ -934,6 +935,18 @@ void ConditionMgr::LoadConditions(bool isReload)          TC_LOG_INFO("misc", "Re-Loading `gossip_menu_option` Table for Conditions!");          sObjectMgr->LoadGossipMenuItems();          sSpellMgr->UnloadSpellInfoImplicitTargetConditionLists(); + +        TC_LOG_INFO("misc", "Re-Loading `terrain_phase_info` Table for Conditions!"); +        sObjectMgr->LoadTerrainPhaseInfo(); + +        TC_LOG_INFO("misc", "Re-Loading `terrain_swap_defaults` Table for Conditions!"); +        sObjectMgr->LoadTerrainSwapDefaults(); + +        TC_LOG_INFO("misc", "Re-Loading `terrain_worldmap` Table for Conditions!"); +        sObjectMgr->LoadTerrainWorldMaps(); + +        TC_LOG_INFO("misc", "Re-Loading `phase_area` Table for Conditions!"); +        sObjectMgr->LoadAreaPhases();      }      QueryResult result = WorldDatabase.Query("SELECT SourceTypeOrReferenceId, SourceGroup, SourceEntry, SourceId, ElseGroup, ConditionTypeOrReference, ConditionTarget, " @@ -1135,6 +1148,9 @@ void ConditionMgr::LoadConditions(bool isReload)                      ++count;                      continue;                  } +                case CONDITION_SOURCE_TYPE_PHASE: +                    valid = addToPhases(cond); +                    break;                  default:                      break;              } @@ -1151,6 +1167,17 @@ void ConditionMgr::LoadConditions(bool isReload)              }              continue;          } +        else if (cond->SourceType == CONDITION_SOURCE_TYPE_TERRAIN_SWAP) +        { +            if (!addToTerrainSwaps(cond)) +            { +                delete cond; +                continue; +            } + +            ++count; +            continue; +        }          //handle not grouped conditions          //make sure we have a storage list for our SourceType @@ -1334,6 +1361,62 @@ bool ConditionMgr::addToSpellImplicitTargetConditions(Condition* cond)      return true;  } +static bool addToTerrainSwapStore(TerrainPhaseInfo& swaps, Condition* cond) +{ +    bool added = false; +    for (auto itr = swaps.begin(); itr != swaps.end(); ++itr) +        for (auto it2 = itr->second.begin(); it2 != itr->second.end(); ++it2) +            if (it2->Id == uint32(cond->SourceEntry)) +                it2->Conditions.push_back(cond), added = true; + +    return added; +} + +bool ConditionMgr::addToTerrainSwaps(Condition* cond) +{ +    bool added = false; +    added = addToTerrainSwapStore(sObjectMgr->GetPhaseTerrainSwapStoreForLoading(), cond); +    added = addToTerrainSwapStore(sObjectMgr->GetDefaultTerrainSwapStoreForLoading(), cond) || added; +    if (added) +        return true; + +    TC_LOG_ERROR("sql.sql", "%s No terrain swap with map %u exists.", cond->ToString().c_str(), cond->SourceEntry); +    return false; +} + +bool ConditionMgr::addToPhases(Condition* cond) +{ +    if (!cond->SourceEntry) +    { +        PhaseInfo& p = sObjectMgr->GetAreaPhasesForLoading(); +        for (auto phaseItr = p.begin(); phaseItr != p.end(); ++phaseItr) +        { +            for (PhaseInfoStruct& phase : phaseItr->second) +            { +                if (phase.Id == cond->SourceGroup) +                { +                    phase.Conditions.push_back(cond); +                    return true; +                } +            } +        } +    } +    else if (std::vector<PhaseInfoStruct>* phases = sObjectMgr->GetPhasesForAreaForLoading(cond->SourceEntry)) +    { +        for (PhaseInfoStruct& phase : *phases) +        { +            if (phase.Id == cond->SourceGroup) +            { +                phase.Conditions.push_back(cond); +                return true; +            } +        } +    } + +    TC_LOG_ERROR("sql.sql", "%s Area %u does not have phase %u.", cond->ToString().c_str(), cond->SourceGroup, cond->SourceEntry); +    return false; +} +  bool ConditionMgr::isSourceTypeValid(Condition* cond)  {      if (cond->SourceType == CONDITION_SOURCE_TYPE_NONE || cond->SourceType >= CONDITION_SOURCE_TYPE_MAX) @@ -1674,12 +1757,28 @@ bool ConditionMgr::isSourceTypeValid(Condition* cond)              }              break;          } +        case CONDITION_SOURCE_TYPE_TERRAIN_SWAP: +        { +            if (!sMapStore.LookupEntry(cond->SourceEntry)) +            { +                TC_LOG_ERROR("sql.sql", "%s SourceEntry in `condition` table, does not exist in Map.dbc, ignoring.", cond->ToString().c_str()); +                return false; +            } +            break; +        } +        case CONDITION_SOURCE_TYPE_PHASE: +        { +            if (cond->SourceEntry && !GetAreaEntryByAreaID(cond->SourceEntry)) +            { +                TC_LOG_ERROR("sql.sql", "%s SourceEntry in `condition` table, does not exist in AreaTable.dbc, ignoring.", cond->ToString().c_str()); +                return false; +            } +            break; +        }          case CONDITION_SOURCE_TYPE_GOSSIP_MENU:          case CONDITION_SOURCE_TYPE_GOSSIP_MENU_OPTION:          case CONDITION_SOURCE_TYPE_SMART_EVENT:          case CONDITION_SOURCE_TYPE_NONE: -        case CONDITION_SOURCE_TYPE_TERRAIN_SWAP: -        case CONDITION_SOURCE_TYPE_PHASE:          default:              break;      }  | 
