From 821bb9fcc4dd6b762d7af9ea8fdc6b17dcf9dec2 Mon Sep 17 00:00:00 2001 From: NoFantasy Date: Tue, 17 Aug 2010 19:47:41 +0200 Subject: [PATCH] [10365] Implement ACTION_T_MOUNT_TO_ENTRY_OR_MODEL (43) for creature eventAI. Read doc/EventAI.txt for details. SQL query to update existing scripts are included (convert from using ACTION_T_SET_UNIT_FIELD, field 68) Signed-off-by: NoFantasy --- doc/EventAI.txt | 1 + sql/mangos.sql | 2 +- .../10365_01_mangos_creature_ai_scripts.sql | 5 ++++ sql/updates/Makefile.am | 2 ++ src/game/CreatureEventAI.cpp | 22 +++++++++++++++++ src/game/CreatureEventAI.h | 7 ++++++ src/game/CreatureEventAIMgr.cpp | 24 +++++++++++++++++++ src/shared/revision_nr.h | 2 +- src/shared/revision_sql.h | 2 +- 9 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 sql/updates/10365_01_mangos_creature_ai_scripts.sql diff --git a/doc/EventAI.txt b/doc/EventAI.txt index d850d34ec..4e8a1c26b 100644 --- a/doc/EventAI.txt +++ b/doc/EventAI.txt @@ -142,6 +142,7 @@ For all ACTION_T_RANDOM, When a Particular Param is selected for the Event... Th 40 ACTION_T_SET_SHEATH Sheath Sets sheath state for a creature (0 = no weapon, 1 = melee weapon, 2 = ranged weapon). 41 ACTION_T_FORCE_DESPAWN Delay Despawns the creature, if delay = 0 immediate otherwise will despawn after delay time set in Param1 (in ms). 42 ACTION_T_SET_INVINCIBILITY_HP_LEVEL HP_Level, HP_Percent Set min. health level for creature that can be set at damage as flat value or percent from max health +43 ACTION_T_MOUNT_TO_ENTRY_OR_MODEL CreatureEntry, ModelId Set mount model from creature_template.entry (Param1) OR explicit modelId (Param2). If (Param1) AND (Param2) are both 0, unmount. * = Use -1 where the param is expected to do nothing. Random constant is generated for each event, so if you have a random yell and a random sound, they will be linked up with each other (ie. param2 with param2). diff --git a/sql/mangos.sql b/sql/mangos.sql index f17b1ddaf..74cdd21f2 100644 --- a/sql/mangos.sql +++ b/sql/mangos.sql @@ -24,7 +24,7 @@ CREATE TABLE `db_version` ( `version` varchar(120) default NULL, `creature_ai_version` varchar(120) default NULL, `cache_id` int(10) default '0', - `required_10362_01_mangos_creature_movement_template` bit(1) default NULL + `required_10365_01_mangos_creature_ai_scripts` bit(1) default NULL ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=FIXED COMMENT='Used DB version notes'; -- diff --git a/sql/updates/10365_01_mangos_creature_ai_scripts.sql b/sql/updates/10365_01_mangos_creature_ai_scripts.sql new file mode 100644 index 000000000..39c695c2d --- /dev/null +++ b/sql/updates/10365_01_mangos_creature_ai_scripts.sql @@ -0,0 +1,5 @@ +ALTER TABLE db_version CHANGE COLUMN required_10362_01_mangos_creature_movement_template required_10365_01_mangos_creature_ai_scripts bit; + +UPDATE creature_ai_scripts SET action1_type=43, action1_param1=0 WHERE action1_type=17 AND action1_param1=68; +UPDATE creature_ai_scripts SET action2_type=43, action2_param1=0 WHERE action2_type=17 AND action2_param1=68; +UPDATE creature_ai_scripts SET action3_type=43, action3_param1=0 WHERE action3_type=17 AND action3_param1=68; diff --git a/sql/updates/Makefile.am b/sql/updates/Makefile.am index 7670ea856..f591aeb9b 100644 --- a/sql/updates/Makefile.am +++ b/sql/updates/Makefile.am @@ -81,6 +81,7 @@ pkgdata_DATA = \ 10353_01_mangos_mangos_string.sql \ 10353_02_mangos_command.sql \ 10362_01_mangos_creature_movement_template.sql \ + 10365_01_mangos_creature_ai_scripts.sql \ README ## Additional files to include when running 'make dist' @@ -142,4 +143,5 @@ EXTRA_DIST = \ 10353_01_mangos_mangos_string.sql \ 10353_02_mangos_command.sql \ 10362_01_mangos_creature_movement_template.sql \ + 10365_01_mangos_creature_ai_scripts.sql \ README diff --git a/src/game/CreatureEventAI.cpp b/src/game/CreatureEventAI.cpp index 711d1be84..a8607abc3 100644 --- a/src/game/CreatureEventAI.cpp +++ b/src/game/CreatureEventAI.cpp @@ -804,6 +804,28 @@ void CreatureEventAI::ProcessAction(CreatureEventAI_Action const& action, uint32 m_InvinceabilityHpLevel = action.invincibility_hp_level.hp_level; break; } + case ACTION_T_MOUNT_TO_ENTRY_OR_MODEL: + { + if (action.mount.creatureId || action.mount.modelId) + { + // set model based on entry from creature_template + if (action.mount.creatureId) + { + if (CreatureInfo const* cInfo = GetCreatureTemplateStore(action.mount.creatureId)) + { + uint32 display_id = Creature::ChooseDisplayId(0, cInfo); + m_creature->Mount(display_id); + } + } + //if no param1, then use value from param2 (modelId) + else + m_creature->Mount(action.mount.modelId); + } + else + m_creature->Unmount(); + + break; + } } } diff --git a/src/game/CreatureEventAI.h b/src/game/CreatureEventAI.h index c7abfd55a..a042f2ba3 100644 --- a/src/game/CreatureEventAI.h +++ b/src/game/CreatureEventAI.h @@ -109,6 +109,7 @@ enum EventAI_ActionType ACTION_T_SET_SHEATH = 40, // Sheath (0-passive,1-melee,2-ranged) ACTION_T_FORCE_DESPAWN = 41, // No Params ACTION_T_SET_INVINCIBILITY_HP_LEVEL = 42, // MinHpValue, format(0-flat,1-percent from max health) + ACTION_T_MOUNT_TO_ENTRY_OR_MODEL = 43, // Creature_template entry(param1) OR ModelId (param2) (or 0 for both to unmount) ACTION_T_END, }; @@ -377,6 +378,12 @@ struct CreatureEventAI_Action uint32 hp_level; uint32 is_percent; } invincibility_hp_level; + // ACTION_T_MOUNT_TO_ENTRY_OR_MODEL = 43 + struct + { + uint32 creatureId; // set one from fields (or 0 for both to dismount) + uint32 modelId; + } mount; // RAW struct { diff --git a/src/game/CreatureEventAIMgr.cpp b/src/game/CreatureEventAIMgr.cpp index 05f9f4d93..6f058e951 100644 --- a/src/game/CreatureEventAIMgr.cpp +++ b/src/game/CreatureEventAIMgr.cpp @@ -750,6 +750,30 @@ void CreatureEventAIMgr::LoadCreatureEventAI_Scripts() } } break; + case ACTION_T_MOUNT_TO_ENTRY_OR_MODEL: + if (action.mount.creatureId != 0 || action.mount.modelId != 0) + { + if (action.mount.creatureId && !sCreatureStorage.LookupEntry(action.mount.creatureId)) + { + sLog.outErrorDb("CreatureEventAI: Event %u Action %u uses nonexistent Creature entry %u.", i, j+1, action.mount.creatureId); + action.morph.creatureId = 0; + } + + if (action.mount.modelId) + { + if (action.mount.creatureId) + { + sLog.outErrorDb("CreatureEventAI: Event %u Action %u have unused ModelId %u with also set creature id %u.", i, j+1, action.mount.modelId, action.mount.creatureId); + action.mount.modelId = 0; + } + else if (!sCreatureDisplayInfoStore.LookupEntry(action.mount.modelId)) + { + sLog.outErrorDb("CreatureEventAI: Event %u Action %u uses nonexistent ModelId %u.", i, j+1, action.mount.modelId); + action.mount.modelId = 0; + } + } + } + break; case ACTION_T_EVADE: //No Params case ACTION_T_FLEE_FOR_ASSIST: //No Params case ACTION_T_DIE: //No Params diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index 4e891ca2a..c164358a9 100644 --- a/src/shared/revision_nr.h +++ b/src/shared/revision_nr.h @@ -1,4 +1,4 @@ #ifndef __REVISION_NR_H__ #define __REVISION_NR_H__ - #define REVISION_NR "10364" + #define REVISION_NR "10365" #endif // __REVISION_NR_H__ diff --git a/src/shared/revision_sql.h b/src/shared/revision_sql.h index 7fef34775..777768186 100644 --- a/src/shared/revision_sql.h +++ b/src/shared/revision_sql.h @@ -1,6 +1,6 @@ #ifndef __REVISION_SQL_H__ #define __REVISION_SQL_H__ #define REVISION_DB_CHARACTERS "required_10332_02_characters_pet_aura" - #define REVISION_DB_MANGOS "required_10362_01_mangos_creature_movement_template" + #define REVISION_DB_MANGOS "required_10365_01_mangos_creature_ai_scripts" #define REVISION_DB_REALMD "required_10008_01_realmd_realmd_db_version" #endif // __REVISION_SQL_H__