Пример #1
0
 static function buildSAIAction($eaiItem)
 {
     $result = array();
     for ($i = 1; $i <= 3; $i++) {
         $eaiAction = $eaiItem->{'action' . $i . '_type'};
         if ($eaiAction == 0) {
             break;
         }
         $param1 = $eaiItem->{'action' . $i . '_param1'};
         $param2 = $eaiItem->{'action' . $i . '_param2'};
         $param3 = $eaiItem->{'action' . $i . '_param3'};
         switch ($eaiAction) {
             case ACTION_T_TEXT:
                 $creatureAiTextEntry = Factory::createOrGetDBHandler()->query("SELECT * FROM `creature_ai_texts` WHERE `entry` IN (" . $param1 . "," . $param2 . "," . $param3 . ")")->fetchAll(PDO::FETCH_OBJ);
                 $result[$i] = array('extraData' => $creatureAiTextEntry, 'eaiActionParams' => array($param1, $param2, $param3), 'SAIAction' => SMART_ACTION_TALK, 'params' => array($param1, 0, 0, 0, 0, 0), 'target' => SMART_TARGET_SELF, 'commentType' => "_npcName_ - _eventName_ - Say Line _lineEntry_");
                 for ($x = 0; $x < sizeof($creatureAiTextEntry); $x++) {
                     $content_default = $creatureAiTextEntry[$x]->content_default;
                     if (strpos($content_default, '$C') !== false || strpos($content_default, '$c') !== false || strpos($content_default, '$R') !== false || strpos($content_default, '$r') !== false || strpos($content_default, '$N') !== false || strpos($content_default, '$n') !== false || strpos($content_default, '$T') !== false || strpos($content_default, '$t') !== false || strpos($content_default, '$G') !== false || strpos($content_default, '$g') !== false || strpos($content_default, '%T') !== false || strpos($content_default, '%t') !== false) {
                         $result[$i]['target'] = SMART_TARGET_ACTION_INVOKER;
                         break;
                     }
                 }
                 break;
             case ACTION_T_SET_FACTION:
                 $result[$i] = array('SAIAction' => SMART_ACTION_SET_FACTION, 'params' => array($param1, 0, 0, 0, 0, 0), 'commentType' => "_npcName_ - _eventName_ - Set Faction " . $param1);
                 break;
             case ACTION_T_MORPH_TO_ENTRY_OR_MODEL:
                 $result[$i] = array('SAIAction' => SMART_ACTION_MORPH_TO_ENTRY_OR_MODEL, 'params' => array($param1, $param2, 0, 0, 0, 0), 'commentType' => "_npcName_ - _eventName_ - Set Displayid " . $param1);
                 break;
             case ACTION_T_SOUND:
                 //! Second parameter in SAI means we 'onlySelf' (0 = only self, 1 = everybody around). In EAI this is 0 by default.
                 $result[$i] = array('SAIAction' => SMART_ACTION_SOUND, 'params' => array($param1, 0, 0, 0, 0, 0), 'commentType' => "_npcName_ - _eventName_ - Play Sound " . $param1);
                 break;
             case ACTION_T_EMOTE:
                 $result[$i] = array('SAIAction' => SMART_ACTION_PLAY_EMOTE, 'params' => array($param1, 0, 0, 0, 0, 0), 'commentType' => "_npcName_ - _eventName_ - Emote ");
                 switch ($param1) {
                     case EMOTE_ONESHOT_WAVE_NO_SHEATHE:
                     case EMOTE_ONESHOT_WAVE:
                         $result[$i]['commentType'] .= "Wave";
                         break;
                     case EMOTE_ONESHOT_CHEER_NO_SHEATHE:
                     case EMOTE_ONESHOT_CHEER:
                         $result[$i]['commentType'] .= "Cheer";
                         break;
                     case EMOTE_ONESHOT_LAUGH_NO_SHEATHE:
                     case EMOTE_ONESHOT_LAUGH:
                         $result[$i]['commentType'] .= "Laugh";
                         break;
                     case EMOTE_ONESHOT_EAT_NO_SHEATHE:
                     case EMOTE_ONESHOT_EAT:
                         $result[$i]['commentType'] .= "Eat";
                         break;
                     case EMOTE_STATE_STUN_NO_SHEATHE:
                     case EMOTE_STATE_STUN:
                         $result[$i]['commentType'] .= "Stunned";
                         break;
                     case EMOTE_ONESHOT_SALUTE_NO_SHEATH:
                     case EMOTE_ONESHOT_SALUTE:
                         $result[$i]['commentType'] .= "Salute";
                         break;
                     case EMOTE_STATE_USE_STANDING_NO_SHEATHE:
                     case EMOTE_STATE_USE_STANDING:
                         $result[$i]['commentType'] .= "State Standing";
                         break;
                     case EMOTE_ONESHOT_TALK_NO_SHEATHE:
                     case EMOTE_ONESHOT_TALK:
                         $result[$i]['commentType'] .= "Talk";
                         break;
                     case EMOTE_ONESHOT_POINT_NO_SHEATHE:
                     case EMOTE_ONESHOT_POINT:
                         $result[$i]['commentType'] .= "Point";
                         break;
                     case EMOTE_STATE_EAT_NO_SHEATHE:
                     case EMOTE_STATE_EAT:
                         $result[$i]['commentType'] .= "State Eating";
                         break;
                     case EMOTE_ONESHOT_BOW:
                         $result[$i]['commentType'] .= "Bow";
                         break;
                     case EMOTE_ONESHOT_EXCLAMATION:
                         $result[$i]['commentType'] .= "Exclamation";
                         break;
                     case EMOTE_ONESHOT_QUESTION:
                         $result[$i]['commentType'] .= "Question";
                         break;
                     case EMOTE_STATE_DANCE:
                         $result[$i]['commentType'] .= "State Dance";
                         break;
                     case EMOTE_STATE_SLEEP:
                         $result[$i]['commentType'] .= "State Sleep";
                         break;
                     case EMOTE_STATE_SIT:
                         $result[$i]['commentType'] .= "State Sit";
                         break;
                     case EMOTE_ONESHOT_RUDE:
                         $result[$i]['commentType'] .= "Rude";
                         break;
                     case EMOTE_ONESHOT_ROAR:
                         $result[$i]['commentType'] .= "Roar";
                         break;
                     case EMOTE_ONESHOT_KNEEL:
                         $result[$i]['commentType'] .= "Kneel";
                         break;
                     case EMOTE_ONESHOT_KISS:
                         $result[$i]['commentType'] .= "Kiss";
                         break;
                     case EMOTE_ONESHOT_CRY:
                         $result[$i]['commentType'] .= "Cry";
                         break;
                     case EMOTE_ONESHOT_CHICKEN:
                         $result[$i]['commentType'] .= "Chicken";
                         break;
                     case EMOTE_ONESHOT_BEG:
                         $result[$i]['commentType'] .= "Beg";
                         break;
                     case EMOTE_ONESHOT_APPLAUD:
                         $result[$i]['commentType'] .= "Applaud";
                         break;
                     case EMOTE_ONESHOT_SHOUT:
                         $result[$i]['commentType'] .= "Shout";
                         break;
                     case EMOTE_ONESHOT_FLEX:
                         $result[$i]['commentType'] .= "Flex";
                         break;
                     case EMOTE_ONESHOT_SHY:
                         $result[$i]['commentType'] .= "Shy";
                         break;
                     case EMOTE_STATE_STAND:
                         $result[$i]['commentType'] .= "State Stand";
                         break;
                     case EMOTE_STATE_READY_UNARMED:
                         $result[$i]['commentType'] .= "State Ready Unarmed";
                         break;
                     case EMOTE_STATE_WORK_SHEATHED:
                         $result[$i]['commentType'] .= "State Sheathed";
                         break;
                     case EMOTE_STATE_POINT:
                         $result[$i]['commentType'] .= "State Point";
                         break;
                     case EMOTE_ONESHOT_WOUND:
                         $result[$i]['commentType'] .= "Wounded";
                         break;
                     case EMOTE_ONESHOT_WOUND_CRITICAL:
                         $result[$i]['commentType'] .= "Wounded Critical";
                         break;
                     case EMOTE_ONESHOT_ATTACK_UNARMED:
                         $result[$i]['commentType'] .= "Attack Unarmed";
                         break;
                     case EMOTE_ONESHOT_ATTACK1H:
                         $result[$i]['commentType'] .= "Attack One-Handed";
                         break;
                     case EMOTE_ONESHOT_ATTACK2HTIGHT:
                         $result[$i]['commentType'] .= "Attack Two-Handed Tight";
                         break;
                     case EMOTE_ONESHOT_ATTACK2H_LOOSE:
                         $result[$i]['commentType'] .= "Attack Two-Handed Loose";
                         break;
                     case EMOTE_ONESHOT_PARRY_UNARMED:
                         $result[$i]['commentType'] .= "Parry Unarmed";
                         break;
                     case EMOTE_ONESHOT_PARRY_SHIELD:
                         $result[$i]['commentType'] .= "Parry Shield";
                         break;
                     case EMOTE_ONESHOT_READY_UNARMED:
                         $result[$i]['commentType'] .= "Ready Unarmed";
                         break;
                     case EMOTE_ONESHOT_READY1H:
                         $result[$i]['commentType'] .= "Ready One-Handed";
                         break;
                     case EMOTE_ONESHOT_READY_BOW:
                         $result[$i]['commentType'] .= "Ready Bow";
                         break;
                     case EMOTE_ONESHOT_KICK:
                         $result[$i]['commentType'] .= "Kick";
                         break;
                     case EMOTE_STATE_DEAD:
                         $result[$i]['commentType'] .= "Dead";
                         break;
                     case EMOTE_STATE_KNEEL:
                         $result[$i]['commentType'] .= "State Kneel";
                         break;
                     case EMOTE_ONESHOT_DANCE:
                         $result[$i]['commentType'] .= "Dance";
                         break;
                     case EMOTE_ONESHOT_READY_RIFLE:
                         $result[$i]['commentType'] .= "Ready Rifle";
                         break;
                     case EMOTE_STATE_READY_RIFLE:
                         $result[$i]['commentType'] .= "State Ready Rifle";
                         break;
                     case EMOTE_STATE_WORK_MINING:
                         $result[$i]['commentType'] .= "State Mining";
                         break;
                     case EMOTE_STATE_WORK_CHOPWOOD:
                         $result[$i]['commentType'] .= "State Chopping Wood";
                         break;
                     case EMOTE_STATE_APPLAUD:
                         $result[$i]['commentType'] .= "State Applauding";
                         break;
                     case EMOTE_ONESHOT_YES:
                         $result[$i]['commentType'] .= "Nod";
                         break;
                     case EMOTE_ONESHOT_NO:
                         $result[$i]['commentType'] .= "No";
                         break;
                     case EMOTE_ONESHOT_TRAIN:
                         $result[$i]['commentType'] .= "Train";
                         break;
                     case EMOTE_STATE_SUBMERGED:
                         $result[$i]['commentType'] .= "State Submerged";
                         break;
                     case EMOTE_ONESHOT_SUBMERGE:
                         $result[$i]['commentType'] .= "Submerge";
                         break;
                     case EMOTE_STATE_TALK:
                         $result[$i]['commentType'] .= "State Talking";
                         break;
                     case EMOTE_STATE_FISHING:
                         $result[$i]['commentType'] .= "State Fishing";
                         break;
                     case EMOTE_ONESHOT_FISHING:
                         $result[$i]['commentType'] .= "Fish";
                         break;
                     case EMOTE_ONESHOT_LOOT:
                         $result[$i]['commentType'] .= "Loot";
                         break;
                     case EMOTE_STATE_DROWNED:
                         $result[$i]['commentType'] .= "State Drown";
                         break;
                     case EMOTE_ONESHOT_DROWN:
                         $result[$i]['commentType'] .= "Drown";
                         break;
                     case EMOTE_STATE_ROAR:
                         $result[$i]['commentType'] .= "State Roar";
                         break;
                     case EMOTE_STATE_LAUGH:
                         $result[$i]['commentType'] .= "State Laughing";
                         break;
                     case EMOTE_ONESHOT_CREATURE_SPECIAL:
                         $result[$i]['commentType'] .= "Creature Special";
                         break;
                     case EMOTE_STATE_CANNIBALIZE:
                         $result[$i]['commentType'] .= "State Cannibalize";
                         break;
                     case EMOTE_STATE_LOOT:
                         $result[$i]['commentType'] .= "State Looting";
                         break;
                     case EMOTE_ONESHOT_COWER:
                         $result[$i]['commentType'] .= "Cower";
                         break;
                     case EMOTE_STATE_COWER:
                         $result[$i]['commentType'] .= "State Cowering";
                         break;
                     default:
                         $result[$i]['commentType'] .= $param1;
                         break;
                 }
                 break;
             case ACTION_T_RANDOM_EMOTE:
                 $result[$i] = array('SAIAction' => SMART_ACTION_RANDOM_EMOTE, 'params' => array($param1, $param2, $param3, 0, 0, 0), 'commentType' => "_npcName_ - _eventName_ - Random Emote");
                 break;
             case ACTION_T_CAST:
                 $result[$i] = array('SAIAction' => SMART_ACTION_CAST, 'params' => array($param1, $param3, 0, 0, 0, 0), 'target' => $param2 + 1, 'commentType' => "_npcName_ - _eventName_ - Cast _castSpellId_");
                 break;
             case ACTION_T_THREAT_SINGLE_PCT:
                 $target = $param2 + 1;
             case ACTION_T_THREAT_ALL_PCT:
                 //! Wiki is wrong here, we can have two arguments. First is added threat, second is removed threat.
                 //! Threat addition has priority over threat reduction!
                 //! Wiki updated.
                 $result[$i] = array('SAIAction' => $eaiAction == ACTION_T_THREAT_SINGLE_PCT ? SMART_ACTION_THREAT_SINGLE_PCT : SMART_ACTION_THREAT_ALL_PCT, 'params' => array(max(0, $param1), max(0, -$param1), 0, 0, 0, 0), 'commentType' => "_npcName_ - _eventName_ - ");
                 if (isset($target)) {
                     $result[$i]['target'] = $target;
                 }
                 if ($param1 < 0) {
                     $result[$i]['commentType'] .= "Remove " . -$param1 . '% Threat';
                 } else {
                     // if ($param1 > 0)
                     $result[$i]['commentType'] .= "Add " . -$param1 . '% Threat';
                 }
                 break;
             case ACTION_T_QUEST_EVENT_ALL:
                 $result[$i] = array('SAIAction' => SMART_ACTION_CALL_GROUPEVENTHAPPENS, 'params' => array($param1, 0, 0, 0, 0, 0), 'target' => SMART_TARGET_ACTION_INVOKER, 'commentType' => "_npcName_ - _eventName_ - Quest Credit Group");
                 break;
             case ACTION_T_QUEST_EVENT:
                 $result[$i] = array('SAIAction' => SMART_ACTION_CALL_AREAEXPLOREDOREVENTHAPPENS, 'params' => array($param1, 0, 0, 0, 0, 0), 'target' => $param2 + 1, 'commentType' => "_npcName_ - _eventName_ - Quest Credit");
                 break;
             case ACTION_T_CAST_EVENT_ALL:
                 $target = SMART_TARGET_THREAT_LIST;
                 //! This is basically the only difference between the two action types...
             //! This is basically the only difference between the two action types...
             case ACTION_T_CAST_EVENT:
                 $result[$i] = array('SAIAction' => SMART_ACTION_CALL_CASTEDCREATUREORGO, 'params' => array($param1, $param2, 0, 0, 0, 0), 'commentType' => "_npcName_ - _eventName_ - Quest Credit");
                 if (isset($target)) {
                     $result[$i]['target'] = $target;
                     $result[$i]['commentType'] .= " Threathlist";
                 } else {
                     $result[$i]['target'] = $param3 + 1;
                 }
                 $row = Factory::createOrGetDBHandler()->query("SELECT `Title` FROM `quest_template` WHERE `Id`={$param1}")->fetch(PDO::FETCH_OBJ);
                 if ($row) {
                     $result[$i]['commentType'] .= " " . $row->Title;
                 } else {
                     $result[$i]['commentType'] .= " <Unknown Quest Id>";
                 }
                 break;
             case ACTION_T_SET_UNIT_FIELD:
                 //! Parameter 1 is index of field
                 //! Parameter 2 is new value of field
                 //! Parameter 3 is target of some kind
                 switch ($param1) {
                     case 25:
                         //! UNIT_FIELD_POWER1 (set mana to $param2)
                         $result[$i] = array('SAIAction' => SMART_ACTION_SET_POWER, 'params' => array(0, $param2, 0, 0, 0, 0), 'target' => $param3 + 1, 'commentType' => "_npcName_ - _eventName_ - Set Mana To " . $param2);
                         break;
                     case 55:
                         //! UNIT_FIELD_FACTIONTEMPLATE (set faction to $param2)
                         $result[$i] = array('SAIAction' => SMART_ACTION_SET_FACTION, 'params' => array($param2, 0, 0, 0, 0, 0), 'target' => $param3 + 1, 'commentType' => "_npcName_ - _eventName_ - Set Faction " . $param2);
                         break;
                     case 67:
                         //! UNIT_FIELD_DISPLAYID (set displayid to $param2)
                         $result[$i] = array('SAIAction' => SMART_ACTION_MORPH_TO_ENTRY_OR_MODEL, 'params' => array($param2, 0, 0, 0, 0, 0), 'target' => $param3 + 1, 'commentType' => "_npcName_ - _eventName_ - Set Displayid " . $param2);
                         break;
                     case 69:
                         //! UNIT_FIELD_MOUNTDISPLAYID (set mount display to $param2)
                         //! Becomes SMART_ACTION_MOUNT_TO_ENTRY_OR_MODEL (which sets UNIT_FIELD_MOUNTDISPLAYID)
                         $result[$i] = array('SAIAction' => SMART_ACTION_MOUNT_TO_ENTRY_OR_MODEL, 'params' => array(0, $param2, 0, 0, 0, 0), 'target' => $param3 + 1, 'commentType' => "_npcName_ - _eventName_ - Mount Up Model " . $param2);
                         if ($param2 == 0) {
                             $result[$i]['commentType'] = "_npcName_ - _eventName_ - Dismount";
                         }
                         break;
                     case 74:
                         //! UNIT_FIELD_BYTES_1 (set bytes1 to $param2)
                         $result[$i] = array('SAIAction' => SMART_ACTION_SET_UNIT_FIELD_BYTES_1, 'params' => array($param2, 0, 0, 0, 0, 0), 'target' => $param3 + 1, 'commentType' => "_npcName_ - _eventName_ - " . Utils::getCommentForByte1Flag($param2));
                         break;
                     default:
                         //! None...
                         $result[$i] = array('SAIAction' => __FIXME__, 'params' => array(__FIXME__, __FIXME__, __FIXME__, __FIXME__, __FIXME__, __FIXME__), 'commentType' => "_npcName_ - _eventName_ - Unsupported unit field id " . $param1);
                         break;
                 }
                 break;
             case ACTION_T_SET_UNIT_FLAG:
                 $result[$i] = array('SAIAction' => SMART_ACTION_SET_UNIT_FLAG, 'params' => array($param1, 0, 0, 0, 0, 0), 'target' => $param2 + 1, 'commentType' => "_npcName_ - _eventName_ - Set " . Utils::getCommentForUnitFlags($param1) . " Flag");
                 break;
             case ACTION_T_REMOVE_UNIT_FLAG:
                 $result[$i] = array('SAIAction' => SMART_ACTION_REMOVE_UNIT_FLAG, 'params' => array($param1, 0, 0, 0, 0, 0), 'target' => $param2 + 1, 'commentType' => "_npcName_ - _eventName_ - Remove " . Utils::getCommentForUnitFlags($param1) . " Flag");
                 break;
             case ACTION_T_AUTO_ATTACK:
                 $result[$i] = array('SAIAction' => SMART_ACTION_AUTO_ATTACK, 'params' => array($param1, 0, 0, 0, 0, 0), 'commentType' => "_npcName_ - _eventName_ - " . ($param1 == 0 ? "Stop" : "Start") . " Auto Attack");
                 break;
             case ACTION_T_COMBAT_MOVEMENT:
                 $result[$i] = array('SAIAction' => SMART_ACTION_ALLOW_COMBAT_MOVEMENT, 'params' => array($param1, 0, 0, 0, 0, 0), 'commentType' => "_npcName_ - _eventName_ - " . ($param1 == 0 ? "Disallow" : "Allow") . " Combat Movement");
                 break;
             case ACTION_T_SET_PHASE:
                 $result[$i] = array('SAIAction' => SMART_ACTION_SET_EVENT_PHASE, 'params' => array($param1, 0, 0, 0, 0, 0), 'commentType' => "_npcName_ - _eventName_ - Set Event Phase " . $param1);
                 break;
             case ACTION_T_INC_PHASE:
                 $result[$i] = array('SAIAction' => SMART_ACTION_INC_EVENT_PHASE, 'params' => array(0, 0, 0, 0, 0, 0), 'commentType' => "_npcName_ - _eventName_ - Increment Event Phase");
                 if ($param1 < 0) {
                     //! -$param1 because it's negative in EAI and should be positive in SAI (double negative = positive).
                     $result[$i]['params'] = array(0, -$param1, 0, 0, 0, 0);
                     $result[$i]['commentType'] = "_npcName_ - _eventName_ - Decrement Event Phase";
                 } else {
                     $result[$i]['params'] = array($param1, 0, 0, 0, 0, 0);
                 }
                 break;
             case ACTION_T_EVADE:
                 $result[$i] = array('SAIAction' => SMART_ACTION_EVADE, 'params' => array(0, 0, 0, 0, 0, 0), 'commentType' => "_npcName_ - _eventName_ - Evade");
                 break;
             case ACTION_T_FLEE_FOR_ASSIST:
                 //! EAI has no parameter. I set the first one as 0 as default for the NPC not to emote when fleeing.
                 //! EAI needs another action for this. WE DONT. This action will be used to pick if we need to emote
                 //! on fleeing.
                 $result[$i] = array('SAIAction' => SMART_ACTION_FLEE_FOR_ASSIST, 'params' => array(0, 0, 0, 0, 0, 0), 'target' => SMART_TARGET_NONE, 'commentType' => "_npcName_ - _eventName_ - Flee For Assist");
                 break;
             case ACTION_T_REMOVEAURASFROMSPELL:
                 $result[$i] = array('SAIAction' => SMART_ACTION_REMOVEAURASFROMSPELL, 'params' => array($param2, 0, 0, 0, 0, 0), 'target' => $param1 + 1, 'commentType' => "_npcName_ - _eventName_ - Remove Aura _removeAuraSpell_");
                 if ($param2 == 0) {
                     $result[$i]['commentType'] = "_npcName_ - _eventName_ - Remova All Auras";
                 }
                 break;
             case ACTION_T_RANGED_MOVEMENT:
                 $result[$i] = array('SAIAction' => SMART_ACTION_SET_RANGED_MOVEMENT, 'params' => array($param1, $param2, 0, 0, 0, 0), 'target' => SMART_TARGET_SELF, 'commentType' => "_npcName_ - _eventName_ - Set Ranged Movement Distance " . $param1 . " Angle " . $param2);
                 break;
             case ACTION_T_RANDOM_PHASE:
                 $result[$i] = array('SAIAction' => SMART_ACTION_RANDOM_PHASE, 'params' => array($param1, $param2, $param3, 0, 0, 0), 'commentType' => "_npcName_ - _eventName_ - Set Random Phase");
                 break;
             case ACTION_T_RANDOM_PHASE_RANGE:
                 $result[$i] = array('SAIAction' => SMART_ACTION_RANDOM_PHASE_RANGE, 'params' => array($param1, $param2, 0, 0, 0, 0), 'commentType' => "_npcName_ - _eventName_ - Random Phase Range ({$param1}-{$param2})");
                 break;
             case ACTION_T_SUMMON:
                 //! Forcing SummonType to 1 as EAI doesnt handle it
                 $result[$i] = array('SAIAction' => SMART_ACTION_SUMMON_CREATURE, 'params' => array($param1, 1, $param3, 0, 0, 0), 'target' => $param2 + 1, 'commentType' => "_npcName_ - _eventName_ - Summon Creature " . Factory::createOrGetDBHandler()->query("SELECT `name` FROM `creature_template` WHERE `entry`={$param1}")->fetch(PDO::FETCH_OBJ)->name);
                 break;
             case ACTION_T_SUMMON_ID:
                 //! Forcing SummonType to 1 as EAI doesnt handle it
                 $result[$i] = array('SAIAction' => SMART_ACTION_SUMMON_CREATURE, 'params' => array($param1, 1, 0, 0, 0, 0), 'commentType' => "_npcName_ - _eventName_ - Summon Creature " . Factory::createOrGetDBHandler()->query("SELECT `name` FROM `creature_template` WHERE `entry`={$param1}")->fetch(PDO::FETCH_OBJ)->name, 'isSpecialHandler' => true);
                 break;
             case ACTION_T_KILLED_MONSTER:
                 $result[$i] = array('SAIAction' => SMART_ACTION_CALL_KILLEDMONSTER, 'params' => array($param1, 0, 0, 0, 0, 0), 'target' => $param2 + 1, 'commentType' => "_npcName_ - _eventName_ - Quest Credit");
                 break;
             case ACTION_T_SET_INST_DATA:
                 $result[$i] = array('SAIAction' => SMART_ACTION_SET_INST_DATA, 'params' => array($param1, $param2, 0, 0, 0, 0), 'commentType' => "_npcName_ - _eventName_ - Set Instance Data Field To {$param1} To Data {$param2}");
                 break;
             case ACTION_T_SET_INST_DATA64:
                 $result[$i] = array('SAIAction' => SMART_ACTION_SET_INST_DATA64, 'params' => array($param1, 0, 0, 0, 0, 0), 'target' => $param2 + 1, 'commentType' => "_npcName_ - _eventName_ - Set Instance Data64 Field To {$param1}");
                 break;
             case ACTION_T_UPDATE_TEMPLATE:
                 $result[$i] = array('SAIAction' => SMART_ACTION_UPDATE_TEMPLATE, 'params' => array($param1, $param2, 0, 0, 0, 0), 'commentType' => "_npcName_ - _eventName_ - Update Template To " . Factory::createOrGetDBHandler()->query("SELECT `name` FROM `creature_template` WHERE `entry`={$param1}")->fetch(PDO::FETCH_OBJ)->name);
                 break;
             case ACTION_T_DIE:
                 $result[$i] = array('SAIAction' => SMART_ACTION_DIE, 'params' => array(0, 0, 0, 0, 0, 0), 'commentType' => "_npcName_ - _eventName_ - Die");
                 break;
             case ACTION_T_ZONE_COMBAT_PULSE:
                 $result[$i] = array('SAIAction' => SMART_ACTION_SET_IN_COMBAT_WITH_ZONE, 'params' => array(0, 0, 0, 0, 0, 0), 'commentType' => "_npcName_ - _eventName_ - Set In Combat With Zone");
                 break;
             case ACTION_T_CALL_FOR_HELP:
                 $result[$i] = array('SAIAction' => SMART_ACTION_CALL_FOR_HELP, 'params' => array($param1, 0, 0, 0, 0, 0), 'commentType' => "_npcName_ - _eventName_ - Call For Help");
                 break;
             case ACTION_T_SET_SHEATH:
                 $result[$i] = array('SAIAction' => SMART_ACTION_SET_SHEATH, 'params' => array($param1, 0, 0, 0, 0, 0), 'commentType' => "_npcName_ - _eventName_ - Set Sheath ");
                 switch ($param1) {
                     case 0:
                         // No melee weapon
                         $result[$i]['commentType'] .= 'Unarmed';
                         break;
                     case 1:
                         // Melee weapon
                         $result[$i]['commentType'] .= 'Melee';
                         break;
                     case 2:
                         // Ranged
                         $result[$i]['commentType'] .= 'Ranged';
                         break;
                     default:
                         $result[$i]['commentType'] .= 'UNKNOWN';
                         break;
                 }
                 break;
             case ACTION_T_FORCE_DESPAWN:
                 $result[$i] = array('SAIAction' => SMART_ACTION_FORCE_DESPAWN, 'params' => array($param1, 0, 0, 0, 0, 0), 'commentType' => "_npcName_ - _eventName_ - Forced Despawn");
                 if ($param1 > 0) {
                     $result[$i]['commentType'] .= " In " . $param1 . " Ms";
                 }
                 break;
             case ACTION_T_SET_INVINCIBILITY_HP_LEVEL:
                 $result[$i] = array('SAIAction' => SMART_ACTION_SET_INVINCIBILITY_HP_LEVEL, 'params' => array($param1, 0, 0, 0, 0, 0), 'commentType' => "_npcName_ - _eventName_ - Set Invincibility Health To " . $param1);
                 //! In EAI, the action had two parameters: parameter 1 for the invincibility HP, param2 to decide
                 //! whether or not param1 would be pct or flat HP (1 = pct, 0 = flat).
                 //! In SAI, the action has two parameters as well: parameter 1 for the flat invincibility HP and
                 //! parameter 2 for the pct invincibility HP.
                 if ($param2 > 0) {
                     $result[$i]['commentType'] .= "%";
                     $result[$i]['params'] = array(0, $param1, 0, 0, 0, 0);
                 }
                 break;
             case ACTION_T_MOUNT_TO_ENTRY_OR_MODEL:
                 $result[$i] = array('SAIAction' => SMART_ACTION_MOUNT_TO_ENTRY_OR_MODEL, 'params' => array($param1, $param2, 0, 0, 0, 0), 'commentType' => "_npcName_ - _eventName_ - Mount Up " . ($param1 ? "Entry" : "Model") . $param1);
                 if ($param1 == 0 && $param2 == 0) {
                     $result[$i]['commentType'] = "_npcName_ - _eventName_ - Dismount";
                 }
                 break;
             case ACTION_T_SET_PHASE_MASK:
                 $result[$i] = array('SAIAction' => SMART_ACTION_SET_INGAME_PHASE_MASK, 'params' => array($param1, 0, 0, 0, 0, 0), 'commentType' => "_npcName_ - _eventName_ - Set Phasemask " . $param1);
                 break;
             case ACTION_T_SET_STAND_STATE:
                 $result[$i] = array('SAIAction' => SMART_ACTION_SET_UNIT_FIELD_BYTES_1, 'params' => array(0, $param1, 0, 0, 0, 0), 'target' => SMART_TARGET_SELF, 'commentType' => "_npcName_ - _eventName_ - " . Utils::getCommentForByte1Flag($param2));
                 break;
             case ACTION_T_MOVE_RANDOM_POINT:
                 $result[$i] = array('SAIAction' => SMART_ACTION_RANDOM_MOVE, 'params' => array($param1, 0, 0, 0, 0, 0), 'commentType' => "_npcName_ - _eventName_ - Move Random");
                 break;
             case ACTION_T_SET_VISIBILITY:
                 $result[$i] = array('SAIAction' => SMART_ACTION_SET_VISIBILITY, 'params' => array($param1, 0, 0, 0, 0, 0), 'commentType' => "_npcName_ - _eventName_ - Set Visiblity " . ($param1 == 0 ? "Off" : "On"));
                 break;
             case ACTION_T_SET_ACTIVE:
                 $result[$i] = array('SAIAction' => SMART_ACTION_SET_ACTIVE, 'params' => array($param1, 0, 0, 0, 0, 0), 'commentType' => "_npcName_ - _eventName_ - Set Active " . ($param1 == 0 ? "Off" : "On"));
                 break;
             case ACTION_T_SET_AGGRESSIVE:
                 //! The naming of the EAI action type is wrong. Core handling simply goes like this:
                 //! me->SetReactState(ReactStates(action.raw.param1));
                 //! Therefore making it work the same as SMART_ACTION_SET_REACT_STATE and not setting
                 //! the source to aggressive.
                 $result[$i] = array('SAIAction' => SMART_ACTION_SET_REACT_STATE, 'params' => array($param1, 0, 0, 0, 0, 0), 'commentType' => "_npcName_ - _eventName_ - Set Reactstate ");
                 switch ($param1) {
                     case 0:
                         $result[$i]['commentType'] .= "Passive";
                         break;
                     case 1:
                         $result[$i]['commentType'] .= "Defensive";
                         break;
                     case 2:
                         $result[$i]['commentType'] .= "Aggressive";
                         break;
                     default:
                         $result[$i]['commentType'] .= "UNKNOWN";
                         break;
                 }
                 break;
             case ACTION_T_ATTACK_START_PULSE:
                 //! ACTION_T_ATTACK_START_PULSE by default targets closest enemy within given range (param1), which we
                 //! therefore pass on as target_param1 for SMART_TARGET_CLOSEST_ENEMY.
                 $result[$i] = array('SAIAction' => SMART_ACTION_ATTACK_START, 'params' => array(0, 0, 0, 0, 0, 0), 'target' => SMART_TARGET_CLOSEST_ENEMY, 'target_params' => array($param1, 0, 0), 'commentType' => "_npcName_ - _eventName_ - Attack Start");
                 break;
             case ACTION_T_SUMMON_GO:
                 $result[$i] = array('SAIAction' => SMART_ACTION_SUMMON_GO, 'params' => array($param1, $param2, 0, 0, 0, 0), 'commentType' => "_npcName_ - _eventName_ - Summon Gameobject " . Factory::createOrGetDBHandler()->query("SELECT name FROM gameobject_template WHERE entry = {$param1}")->fetch(PDO::FETCH_OBJ)->name);
                 break;
             case ACTION_T_NONE:
                 $result[$i] = array('SAIAction' => SMART_ACTION_NONE, 'params' => array(0, 0, 0, 0, 0, 0), 'commentType' => "_npcName_ - _eventName_ - UNUSED");
                 break;
                 //! Need to be handled by random action scripts (thus scripted by hand).
             //! Need to be handled by random action scripts (thus scripted by hand).
             case ACTION_T_RANDOM_TEXTEMOTE:
             default:
                 $result[$i] = array('SAIAction' => __FIXME__, 'params' => array(__FIXME__, __FIXME__, __FIXME__, __FIXME__, __FIXME__, __FIXME__), 'commentType' => "_npcName_ - _eventName_ - Y me not working ??? :(");
                 break;
         }
         if (!isset($result[$i]['extraData'])) {
             $result[$i]['extraData'] = 0;
         }
         if (!isset($result[$i]['eaiActionParams'])) {
             $result[$i]['eaiActionParams'] = 0;
         }
         if (!isset($result[$i]['isSpecialHandler'])) {
             $result[$i]['isSpecialHandler'] = false;
         }
         if (!isset($result[$i]['target'])) {
             $result[$i]['target'] = SMART_TARGET_SELF;
         }
         if (!isset($result[$i]['target_params'])) {
             $result[$i]['target_params'] = array(0, 0, 0);
         }
         if (!isset($result[$i]['target_paramCoords'])) {
             $result[$i]['target_paramCoords'] = array(0, 0, 0, 0);
         }
     }
     return $result;
 }
Пример #2
0
 static function buildSAIAction($eaiItem)
 {
     $result = array();
     for ($i = 1; $i <= 3; $i++) {
         $eaiAction = $eaiItem->{'action' . $i . '_type'};
         if ($eaiAction == 0) {
             break;
         }
         $param1 = $eaiItem->{'action' . $i . '_param1'};
         $param2 = $eaiItem->{'action' . $i . '_param2'};
         $param3 = $eaiItem->{'action' . $i . '_param3'};
         switch ($eaiAction) {
             case ACTION_T_TEXT:
                 $result[$i] = array('extraData' => Factory::createOrGetDBHandler()->query("SELECT * FROM `creature_ai_texts` WHERE `entry` IN (" . $param1 . "," . $param2 . "," . $param3 . ")")->fetchAll(PDO::FETCH_OBJ), 'SAIAction' => SMART_ACTION_TALK, 'params' => array($param1, $param2, $param3, 0, 0, 0), 'commentType' => "_npcName_ - _eventName_ - Say Line _lineEntry_");
                 break;
             case ACTION_T_SET_FACTION:
                 $result[$i] = array('SAIAction' => SMART_ACTION_SET_FACTION, 'params' => array($param1, $param2, $param3, 0, 0, 0), 'commentType' => "_npcName_ - _eventName_ - Set Faction " . $param1);
                 break;
             case ACTION_T_MORPH_TO_ENTRY_OR_MODEL:
                 $result[$i] = array('SAIAction' => SMART_ACTION_MORPH_TO_ENTRY_OR_MODEL, 'params' => array($param1, $param2, $param3, 0, 0, 0), 'commentType' => "_npcName_ - _eventName_ - Morph Into " . $param1);
                 break;
             case ACTION_T_SOUND:
                 $result[$i] = array('SAIAction' => SMART_ACTION_SOUND, 'params' => array($param1, max(0, min($param2, 1)), 0, 0, 0, 0), 'commentType' => "_npcName_ - _eventName_ - Play Sound " . $param1);
                 break;
             case ACTION_T_EMOTE:
                 $result[$i] = array('SAIAction' => SMART_ACTION_PLAY_EMOTE, 'params' => array($param1, 0, 0, 0, 0, 0), 'commentType' => "_npcName_ - _eventName_ - Play Emote " . $param1);
                 break;
             case ACTION_T_RANDOM_EMOTE:
                 $result[$i] = array('SAIAction' => SMART_ACTION_RANDOM_EMOTE, 'params' => array($param1, $param2, $param3, 0, 0, 0), 'commentType' => "_npcName_ - _eventName_ - Random Emote");
                 break;
             case ACTION_T_CAST:
                 $result[$i] = array('SAIAction' => SMART_ACTION_CAST, 'params' => array($param1, $param3, 0, 0, 0, 0), 'target' => $param2 + 1, 'commentType' => "_npcName_ - _eventName_ - Cast _castSpellId_");
                 break;
             case ACTION_T_THREAT_SINGLE_PCT:
                 $target = $param2 + 1;
             case ACTION_T_THREAT_ALL_PCT:
                 //! Wiki is wrong here, we can have two arguments. First is added threat, second is removed threat.
                 //! Threat addition has priority over threat reduction!
                 $result[$i] = array('SAIAction' => $eaiAction == ACTION_T_THREAT_SINGLE_PCT ? SMART_ACTION_THREAT_SINGLE_PCT : SMART_ACTION_THREAT_ALL_PCT, 'params' => array(max(0, $param1), max(0, -$param1), 0, 0, 0, 0), 'commentType' => "_npcName_ - _eventName_ - ");
                 if (isset($target)) {
                     $result[$i]['target'] = $target;
                 }
                 if ($param1 < 0) {
                     $result[$i]['commentType'] .= "Remove " . -$param1 . '% Threat';
                 } else {
                     // if ($param1 > 0)
                     $result[$i]['commentType'] .= "Add " . -$param1 . '% Threat';
                 }
                 break;
             case ACTION_T_QUEST_EVENT_ALL:
             case ACTION_T_QUEST_EVENT:
                 $result[$i] = array('SAIAction' => SMART_ACTION_CALL_AREAEXPLOREDOREVENTHAPPENS, 'params' => array($param1, 0, 0, 0, 0, 0), 'commentType' => "_npcName_ - _eventName_ - Quest Credit");
                 if ($eaiAction == ACTION_T_QUEST_EVENT) {
                     $result[$i]['target'] = $param2 + 1;
                 }
                 break;
             case ACTION_T_CAST_EVENT_ALL:
             case ACTION_T_CAST_EVENT:
                 $result[$i] = array('SAIAction' => SMART_ACTION_CALL_CASTEDCREATUREORGO, 'params' => array($param1, $param2, 0, 0, 0, 0), 'commentType' => "_npcName_ - _eventName_ - Quest Credit");
                 if ($eaiAction == ACTION_T_CAST_EVENT) {
                     $result[$i]['target'] = $param3 + 1;
                 }
                 break;
             case ACTION_T_SET_UNIT_FIELD:
                 //! Not a  100% sure on this, requires deeper research. (Horn's comments based)
                 //! Not sure if it's param1 or param2!
                 $result[$i] = array('SAIAction' => SMART_ACTION_SET_UNIT_FIELD_BYTES_1, 'params' => array($param2, 0, 0, 0, 0, 0), 'target' => $param3 + 1, 'commentType' => "_npcName_ - _eventName_ - Set Bytes1 " . $param2);
                 break;
             case ACTION_T_SET_UNIT_FLAG:
                 $result[$i] = array('SAIAction' => SMART_ACTION_SET_UNIT_FLAG, 'params' => array($param1, 0, 0, 0, 0, 0), 'target' => $param2 + 1, 'commentType' => "_npcName_ - _eventName_ - Set unit_flag " . $param1);
                 break;
             case ACTION_T_REMOVE_UNIT_FLAG:
                 $result[$i] = array('SAIAction' => SMART_ACTION_REMOVE_UNIT_FLAG, 'params' => array($param1, 0, 0, 0, 0, 0), 'target' => $param2 + 1, 'commentType' => "_npcName_ - _eventName_ - Remove unit_flag " . $param1);
                 break;
             case ACTION_T_AUTO_ATTACK:
                 $result[$i] = array('SAIAction' => SMART_ACTION_AUTO_ATTACK, 'params' => array($param1, 0, 0, 0, 0, 0), 'commentType' => "_npcName_ - _eventName_ - Start Auto Attack");
                 break;
             case ACTION_T_COMBAT_MOVEMENT:
                 $result[$i] = array('SAIAction' => SMART_ACTION_ALLOW_COMBAT_MOVEMENT, 'params' => array($param1, 0, 0, 0, 0, 0), 'commentType' => "_npcName_ - _eventName_ - Allow Combat Movement");
                 break;
             case ACTION_T_SET_PHASE:
                 $result[$i] = array('SAIAction' => SMART_ACTION_SET_EVENT_PHASE, 'params' => array($param1, 0, 0, 0, 0, 0), 'commentType' => "_npcName_ - _eventName_ - Set Phase " . $param1);
                 break;
             case ACTION_T_INC_PHASE:
                 $result[$i] = array('SAIAction' => SMART_ACTION_INC_EVENT_PHASE, 'params' => array(0, 0, 0, 0, 0, 0), 'commentType' => "_npcName_ - _eventName_ - " . ($param1 < 0 ? "De" : "In") . "crement Phase");
                 if ($param1 < 0) {
                     $result[$i]['params'][1] = -$param1;
                 } else {
                     // if ($param1 > 0)
                     $result[$i]['params'][0] = $param1;
                 }
                 break;
             case ACTION_T_EVADE:
                 $result[$i] = array('SAIAction' => SMART_ACTION_EVADE, 'params' => array(0, 0, 0, 0, 0, 0), 'commentType' => "_npcName_ - _eventName_ - Evade");
                 break;
             case ACTION_T_FLEE_FOR_ASSIST:
                 //! EAI has no parameter. I set the first one as 0 as default for the NPC not to emote when fleeing.
                 //! EAI needs another action for this. WE DONT. This action will be used to pick if we need to emote
                 //! on fleeing.
                 $result[$i] = array('SAIAction' => SMART_ACTION_FLEE_FOR_ASSIST, 'params' => array(0, 0, 0, 0, 0, 0), 'target' => SMART_TARGET_NONE, 'commentType' => "_npcName_ - _eventName_ - Flee For Assist");
                 break;
             case ACTION_T_REMOVEAURASFROMSPELL:
                 $result[$i] = array('SAIAction' => SMART_ACTION_REMOVEAURASFROMSPELL, 'params' => array($param2, 0, 0, 0, 0, 0), 'target' => $param1 + 1, 'commentType' => "_npcName_ - _eventName_ - Remove Aura _removeAuraSpell_");
                 if ($param2 == 0) {
                     $result[$i]['commentType'] = "_npcName_ - _eventName_ - Remova all auras";
                 }
                 break;
             case ACTION_T_RANGED_MOVEMENT:
                 $result[$i] = array('SAIAction' => SMART_ACTION_SET_RANGED_MOVEMENT, 'params' => array($param1, $param2, 0, 0, 0, 0), 'target' => SMART_TARGET_SELF, 'commentType' => "_npcName_ - _eventName_ - Set Ranged Movement");
                 break;
             case ACTION_T_RANDOM_PHASE:
                 $result[$i] = array('SAIAction' => SMART_ACTION_RANDOM_PHASE, 'params' => array($param1, $param2, $param3, 0, 0, 0), 'commentType' => "_npcName_ - _eventName_ - Set Random Phase");
                 break;
             case ACTION_T_RANDOM_PHASE_RANGE:
                 //! TODO: Check if EAI is inclusive or exclusive (like SAI)
                 $result[$i] = array('SAIAction' => SMART_ACTION_RANDOM_PHASE_RANGE, 'params' => array($param1, $param2, 0, 0, 0, 0), 'commentType' => "_npcName_ - _eventName_ - Random Phase Range ({$param1} - {$param2})");
                 break;
             case ACTION_T_SUMMON:
                 //! Forcing SummonType to 1 as EAI doesnt handle it
                 $result[$i] = array('SAIAction' => SMART_ACTION_SUMMON_CREATURE, 'params' => array($param1, 1, $param3, 0, 0, 0), 'target' => $param2 + 1, 'commentType' => "_npcName_ - _eventName_ - Summon Creature " . Factory::createOrGetDBHandler()->query("SELECT `name` FROM `creature_template` WHERE `entry`={$param1}")->fetch(PDO::FETCH_OBJ)->name);
                 break;
             case ACTION_T_SUMMON_ID:
                 $result[$i] = array('extraData' => Factory::createOrGetDBHandler()->query("SELECT * FROM `creature_ai_summons` WHERE `id`=" . $param3)->fetch(PDO::FETCH_OBJ), 'SAIAction' => SMART_ACTION_SUMMON_CREATURE, 'params' => array($param1, 0, 0, 0, 0, 0), 'commentType' => "_npcName_ - _eventName_ - Summon Creature " . Factory::createOrGetDBHandler()->query("SELECT `name` FROM `creature_template` WHERE `entry`={$param1}")->fetch(PDO::FETCH_OBJ)->name, 'isSpecialHandler' => true);
                 break;
             case ACTION_T_KILLED_MONSTER:
                 $result[$i] = array('SAIAction' => SMART_ACTION_CALL_KILLEDMONSTER, 'params' => array($param1, 0, 0, 0, 0, 0), 'target' => $param2 + 1, 'commentType' => "_npcName_ - _eventName_ - Quest Credit");
                 break;
             case ACTION_T_SET_INST_DATA:
                 $result[$i] = array('SAIAction' => SMART_ACTION_SET_INST_DATA, 'params' => array($param1, $param2, 0, 0, 0, 0), 'commentType' => "_npcName_ - _eventName_ - Set Instance Data {$param1} to {$param2}");
                 break;
             case ACTION_T_SET_INST_DATA64:
                 $result[$i] = array('SAIAction' => SMART_ACTION_SET_INST_DATA64, 'params' => array($param1, 0, 0, 0, 0, 0), 'target' => $param2 + 1, 'commentType' => "_npcName_ - _eventName_ - Set Instance Data64");
                 break;
             case ACTION_T_UPDATE_TEMPLATE:
                 $result[$i] = array('SAIAction' => SMART_ACTION_UPDATE_TEMPLATE, 'params' => array($param1, $param2, 0, 0, 0, 0), 'commentType' => "_npcName_ - _eventName_ - Update Template");
                 break;
             case ACTION_T_DIE:
                 $result[$i] = array('SAIAction' => SMART_ACTION_DIE, 'params' => array(0, 0, 0, 0, 0, 0), 'commentType' => "_npcName_ - _eventName_ - Die");
                 break;
             case ACTION_T_ZONE_COMBAT_PULSE:
                 $result[$i] = array('SAIAction' => SMART_ACTION_SET_IN_COMBAT_WITH_ZONE, 'params' => array(0, 0, 0, 0, 0, 0), 'commentType' => "_npcName_ - _eventName_ - Set In Combat With Zone");
                 break;
             case ACTION_T_CALL_FOR_HELP:
                 $result[$i] = array('SAIAction' => SMART_ACTION_CALL_FOR_HELP, 'params' => array($param1, 0, 0, 0, 0, 0), 'commentType' => "_npcName_ - _eventName_ - Call For Help");
                 break;
             case ACTION_T_SET_SHEATH:
                 $result[$i] = array('SAIAction' => SMART_ACTION_SET_SHEATH, 'params' => array($param1, 0, 0, 0, 0, 0), 'commentType' => "_npcName_ - _eventName_ - ");
                 switch ($param1) {
                     case 0:
                         // No melee weapon
                         $result[$i]['commentType'] .= 'Set unarmed';
                         break;
                     case 1:
                         // Melee weapon
                         $result[$i]['commentType'] .= 'Display melee weapon';
                         break;
                     case 2:
                         // Ranged
                         $result[$i]['commentType'] .= 'Display ranged weapon';
                         break;
                 }
                 break;
             case ACTION_T_FORCE_DESPAWN:
                 $result[$i] = array('SAIAction' => SMART_ACTION_FORCE_DESPAWN, 'params' => array($param1, 0, 0, 0, 0, 0), 'commentType' => "_npcName_ - _eventName_ - Forced Despawn");
                 break;
             case ACTION_T_SET_INVINCIBILITY_HP_LEVEL:
                 $result[$i] = array('SAIAction' => SMART_ACTION_SET_INVINCIBILITY_HP_LEVEL, 'params' => array($param1, 0, 0, 0, 0, 0), 'commentType' => "_npcName_ - _eventName_ - Set Invincibility Health Pct To " . $param1);
                 break;
             case ACTION_T_MOUNT_TO_ENTRY_OR_MODEL:
                 $result[$i] = array('SAIAction' => SMART_ACTION_MOUNT_TO_ENTRY_OR_MODEL, 'params' => array($param1, $param2, 0, 0, 0, 0), 'commentType' => "_npcName_ - _eventName_ - Mount Up");
                 if ($param1 == 0 && $param2 == 0) {
                     $result[$i]['commentType'] = "_npcName_ - _eventName_ - Dismount";
                 }
                 break;
             case ACTION_T_SET_PHASE_MASK:
                 $result[$i] = array('SAIAction' => SMART_ACTION_SET_INGAME_PHASE_MASK, 'params' => array($param1, 0, 0, 0, 0, 0), 'commentType' => "_npcName_ - _eventName_ - Set Phase");
                 break;
             case ACTION_T_SET_STAND_STATE:
                 $result[$i] = array('SAIAction' => SMART_ACTION_SET_UNIT_FIELD_BYTES_1, 'params' => array(0, 0, 0, 0, 0, 0), 'target' => SMART_TARGET_SELF, 'commentType' => "_npcName_ - _eventName_ - Stand Up");
                 break;
             case ACTION_T_MOVE_RANDOM_POINT:
                 $result[$i] = array('SAIAction' => SMART_ACTION_RANDOM_MOVE, 'params' => array($param1, 0, 0, 0, 0, 0), 'commentType' => "_npcName_ - _eventName_ - Move Random");
                 break;
             case ACTION_T_SET_VISIBILITY:
                 $result[$i] = array('SAIAction' => SMART_ACTION_SET_VISIBILITY, 'params' => array($param1, 0, 0, 0, 0, 0), 'commentType' => "_npcName_ - _eventName_ - Set Visiblity");
                 break;
             case ACTION_T_SET_ACTIVE:
                 //! SAI has no parameter and cannot set a NPC as inactive!
                 $result[$i] = array('SAIAction' => SMART_ACTION_SET_ACTIVE, 'params' => array(0, 0, 0, 0, 0, 0), 'commentType' => "_npcName_ - _eventName_ - Set Active");
                 break;
             case ACTION_T_SET_AGGRESSIVE:
                 $result[$i] = array('SAIAction' => SMART_ACTION_SET_REACT_STATE, 'params' => array($param1, 0, 0, 0, 0, 0), 'commentType' => "_npcName_ - _eventName_ - Set React Aggressive");
                 break;
             case ACTION_T_ATTACK_START_PULSE:
                 $result[$i] = array('SAIAction' => SMART_ACTION_ATTACK_START, 'params' => array(0, 0, 0, 0, 0, 0), 'commentType' => "_npcName_ - _eventName_ - Attack Start");
                 break;
             case ACTION_T_SUMMON_GO:
                 $result[$i] = array('SAIAction' => SMART_ACTION_SUMMON_GO, 'params' => array($param1, $param2, 0, 0, 0, 0), 'commentType' => "_npcName_ - _eventName_ - Summon Gameobject " . Factory::createOrGetDBHandler()->query("SELECT name FROM gameobject_template WHERE entry = {$param1}")->fetch(PDO::FETCH_OBJ)->name);
                 break;
             case ACTION_T_NONE:
                 $result[$i] = array('SAIAction' => SMART_ACTION_NONE, 'params' => array(0, 0, 0, 0, 0, 0), 'commentType' => "_npcName_ - _eventName_ - UNUSED");
                 break;
             case ACTION_T_RANDOM_SOUND:
                 //! No event for this in SAI, needs to be handled though imo
             //! No event for this in SAI, needs to be handled though imo
             case ACTION_T_RANDOM_SAY:
             case ACTION_T_RANDOM_YELL:
             case ACTION_T_RANDOM_TEXTEMOTE:
                 $result[$i] = array('SAIAction' => __FIXME__, 'params' => array(__FIXME__, __FIXME__, __FIXME__, __FIXME__, __FIXME__, __FIXME__), 'commentType' => "_npcName_ - _eventName_ - EAI: RANDOM TALK ACTION - NON IMPLEMENTED BY THE SCRIPT");
                 break;
             default:
                 $result[$i] = array('SAIAction' => __FIXME__, 'params' => array(__FIXME__, __FIXME__, __FIXME__, __FIXME__, __FIXME__, __FIXME__), 'commentType' => "_npcName_ - _eventName_ - UNKNOWN EAI ACTION");
                 break;
         }
         if (!isset($result[$i]['isSpecialHandler'])) {
             $result[$i]['isSpecialHandler'] = false;
         }
         if (!isset($result[$i]['target'])) {
             $result[$i]['target'] = SMART_TARGET_SELF;
         }
     }
     return $result;
 }
Пример #3
0
$EAIDataSet = Factory::createOrGetDBHandler()->query("SELECT a.* FROM creature_ai_scripts a")->fetchAll(PDO::FETCH_OBJ);
ob_start();
echo '>> Gotten ' . count($EAIDataSet) . ' entries in ' . round(microtime(true) - $oldDate, 4) . ' ms' . PHP_EOL;
echo PHP_EOL . 'Grouping entries by NPC ...' . PHP_EOL;
ob_end_flush();
$npcName = "";
// Save the last iterated NPC name
$npcId = 0;
// And its entry in the table.
$npcStore = array();
$oldDate = microtime(true);
$forbiddenNpcs = array();
foreach ($EAIDataSet as $eaiItem) {
    if ($npcId != $eaiItem->creature_id) {
        # New NPC. Create a corresponding NPC class instance.
        $npcInfo = Factory::createOrGetDBHandler()->query('SELECT name, flags_extra FROM creature_template WHERE entry = ' . $eaiItem->creature_id)->fetch(PDO::FETCH_OBJ);
        if ($npcInfo->flags_extra & 1) {
            if (!in_array($npcInfo->name, $forbiddenNpcs)) {
                $forbiddenNpcs[] = $npcInfo->name;
            }
            continue;
        }
        $npcId = $eaiItem->creature_id;
        $npcStore[$npcId] = new NPC($npcId, $npcInfo->name);
    }
    $eaiItem->npcName = $npcName;
    $eaiItem->npcId = $npcId;
    $npcStore[$npcId]->addEAI($eaiItem);
}
unset($eaiItem, $npcName, $npcId, $EAIDataSet);
// Save some memory
Пример #4
0
echo "   \\ \\ \\/\\`'__\\/\\ \\ /' _ `\\/\\ \\ \\ \\/ /\\ \\/\\ \\" . PHP_EOL;
echo "    \\ \\ \\ \\ \\/ \\ \\ \\/\\ \\/\\ \\ \\ \\ \\ \\_\\ \\ \\_\\ \\" . PHP_EOL;
echo "     \\ \\_\\ \\_\\  \\ \\_\\ \\_\\ \\_\\ \\_\\ \\__\\\\/`____ \\" . PHP_EOL;
echo "      \\/_/\\/_/   \\/_/\\/_/\\/_/\\/_/\\/__/ `/___/> \\" . PHP_EOL;
echo "                                 C O R E  /\\___/" . PHP_EOL;
echo "http://TrinityCore.org                    \\/__/\n" . PHP_EOL;
ob_end_flush();
if ($iniFile = parse_ini_file('config.ini')) {
    Factory::setDbData($iniFile['hostname'], $iniFile['userName'], $iniFile['password'], $iniFile['worldDatabase']);
    echo '>> Config file found and parsed sucessfully.' . PHP_EOL;
}
ob_start();
echo PHP_EOL . 'Selecting all SmartAIs from the database ...' . PHP_EOL;
ob_end_flush();
$oldDate = microtime(true);
$SAIDataSet = Factory::createOrGetDBHandler()->query("SELECT a.* FROM smart_scripts a")->fetchAll(PDO::FETCH_OBJ);
ob_start();
echo '>> Gotten ' . count($SAIDataSet) . ' entries in ' . round(microtime(true) - $oldDate, 4) . ' ms' . PHP_EOL;
echo PHP_EOL . 'Grouping entries by NPC ...' . PHP_EOL;
ob_end_flush();
$entryorguid = 0;
// Last iterated entry
$npcStore = array();
$oldDate = microtime(true);
foreach ($SAIDataSet as &$saiItem) {
    if ($entryorguid != $saiItem->entryorguid) {
        # New NPC. Create a corresponding NPC class instance.
        $entryorguid = $saiItem->entryorguid;
        $npcStore[$entryorguid] = array();
    }
    $npcStore[$entryorguid][$saiItem->id] = array('link' => intval($saiItem->link), 'eventType' => intval($saiItem->event_type));
Пример #5
0
$oldDate = microtime(true);
$EAIDataSet = Factory::createOrGetDBHandler()->query("SELECT * FROM creature_ai_scripts ORDER BY id")->fetchAll(PDO::FETCH_OBJ);
ob_start();
echo '>> Gotten ' . count($EAIDataSet) . ' entries in ' . round(microtime(true) - $oldDate, 4) . ' ms' . PHP_EOL;
echo PHP_EOL . 'Grouping entries by NPC ...' . PHP_EOL;
ob_end_flush();
$npcName = "";
// Save the last iterated NPC name
$npcId = 0;
// And its entry in the table.
$npcStore = array();
$oldDate = microtime(true);
foreach ($EAIDataSet as $eaiItem) {
    if ($npcId != $eaiItem->creature_id) {
        # New NPC. Create a corresponding NPC class instance.
        $npcName = Factory::createOrGetDBHandler()->query('SELECT name FROM creature_template WHERE entry = ' . $eaiItem->creature_id)->fetch(PDO::FETCH_OBJ)->name;
        $npcId = $eaiItem->creature_id;
        $npcStore[$npcId] = new NPC($npcId, $npcName);
    }
    $eaiItem->npcName = $npcName;
    $eaiItem->npcId = $npcId;
    $npcStore[$npcId]->addEAI($eaiItem);
}
unset($eaiItem, $npcName, $npcId, $EAIDataSet);
// Save some memory
$storeSize = count($npcStore);
# Delete previous files
if (file_exists('creature_texts.sql')) {
    unlink('creature_texts.sql');
}
if (file_exists('smart_scripts.sql')) {