Changeset 1207
- Timestamp:
- 03/07/2010 10:47:08 AM (6 months ago)
- Location:
- Trunk
- Files:
-
- 7 added
- 4 removed
- 9 modified
-
LUA_ENGINE_COMMANDS.txt (modified) (3 diffs)
-
WOWOBJECTFUNCTIONSDUMP.txt (added)
-
lua/BOSS_ManaTombs_Pandemonius.lua (deleted)
-
lua/BOSS_ManaTombs_Shaffar.lua (deleted)
-
lua/BOSS_ManaTombs_Tavarok.lua (deleted)
-
lua/BOSS_ManaTombs_Yor.lua (deleted)
-
lua/MANA_TOMBS (added)
-
lua/MANA_TOMBS/Instance_ManaTombs.lua (added)
-
lua/MANA_TOMBS/Pandemonius.script (added)
-
lua/MANA_TOMBS/shaffar.script (added)
-
lua/MANA_TOMBS/tavarok.script (added)
-
lua/MANA_TOMBS/yor.script (added)
-
lua/Misc/0LCF_Includes/LCF_Creature.lua (modified) (3 diffs)
-
lua/Misc/0LCF_Includes/LCF_Extra.lua (modified) (2 diffs)
-
lua/Misc/0LCF_Includes/LCF_Gameobject.lua (modified) (1 diff)
-
lua/Misc/0LCF_Includes/LCF_Player.lua (modified) (1 diff)
-
src/LuaEngine/FunctionTables.h (modified) (2 diffs)
-
src/LuaEngine/GameobjectFunctions.h (modified) (1 diff)
-
src/LuaEngine/LUAEngine.cpp (modified) (17 diffs)
-
src/LuaEngine/UnitFunctions.h (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
Trunk/LUA_ENGINE_COMMANDS.txt
r1190 r1207 461 461 - Note : if you want to register a Lua METHOD, then you will have to pass in LCF:BindMethod(method_name,methods_table) for func. method being the lua function and methods_table being the TABLE, method is located in. This goes for the other classes as well. 462 462 RemoveLuaEvent(func) -- removes all events currently registered under the invoking player. Specify func to remove only those events who invoke func. 463 FaceUnit(tar) - makes the Creature face the target specified. 464 GetNearestUnitWithEntry(entry) - returns the nearest unit to the creature with the specified entry. 463 FaceUnit(tar) - makes the Creature face the target specified. 464 GetNearestUnitWithEntry(entry) - returns the nearest unit to the creature with the specified entry. 465 GetLocalCreature(creature_entry) - simply calls GetCreatureNearestCoords with the unit's position. 466 GetLocalGameObject(go_entry) 467 GetCreator() - returns the unit whos guid is stored in UNIT_FIELD_CREATEDBY/SUMMONEDBY 468 SetCreator(creator_obj) - sets UNIT_FIELD_CREATEDBY/SUMMONEDBY to creator_obj:GetGUID() 465 469 Player: 466 470 GetStrength() … … 475 479 RegisterLuaEvent(func,delay,repeats,extra_args_go_here) - same as creature 476 480 RemoveLuaEvent(func) -- same as creature 477 GetNearestUnitWithEntry(entry) - same as creature 481 GetNearestUnitWithEntry(entry) - same as creature 482 GetLocalCreature(creature_entry) - simply calls GetCreatureNearestCoords with the player's position. 483 GetLocalGameObject(go_entry) 478 484 GameObject: 479 485 SetClickable() … … 488 494 RegisterLuaEvent(func,delay,repeats,extra_args_go_here) - same as creature. 489 495 RemoveLuaEvent(func) - same as creature 496 GetCreator() - returns the unit whos guid is stored in OBJECT_FIELD_CREATEDBY 497 SetCreator(creator_obj) - sets OBJECT_FIELD_CREATEDBY to creator_obj:GetGUID() 498 GetLocalCreature(creature_entry) - simply calls GetCreatureNearestCoords with the go's position. 499 GetLocalGameObject(go_entry) 490 500 EXTRA METHODS 491 501 LCF:RegisterZoneHook(zone_id,func) - this takes the desired zone id and a lua function value(not a string unlike RegisterUnitEvent...) It will then call this function when the server hook with the zone id triggers -
Trunk/lua/Misc/0LCF_Includes/LCF_Creature.lua
r1190 r1207 20 20 local CREATURE = LCF.CreatureMethods 21 21 assert(CREATURE) 22 --[[CREATURE.spell_events = {} 23 CREATURE.CAST_FLAG_ON_SELF = 0x0 24 CREATURE.CAST_FLAG_ON_TARGET = 0x1 25 CREATURE.CAST_FLAG_DEST = 0x2 26 CREATURE.CAST_FLAG_ALL_PLAYERS = 0x3 27 CREATURE.CAST_FLAG_FRIENDLY_UNITS = 0x4 28 CREATURE.CAST_FLAG_ENEMY_UNITS = 0x5 29 CREATURE.CAST_ATTRIBUTE_INSTANT = 0x8 -- or 1000B]] 22 30 23 31 function CREATURE:SetUnselectable() … … 68 76 self:SendChatMessage(LCF.CHAT_MSG_MONSTER_EMOTE,LCF.LANG_UNIVERSAL,msg) 69 77 end 78 function CREATURE:MonsterWhisper(msg) 79 self:SendChatMessage(LCF.CHAT_MSG_MONSTER_WHISPER,LCF.LANG_UNIVERSAL,msg) 80 end 70 81 function CREATURE:MoveToUnit(target) 71 82 local x,y,z = target:GetLocation() … … 82 93 LCF:RemoveLuaEvent(tostring(self),func) 83 94 end 84 function CREATURE: GetNearestUnitWithEntry(entry)85 return (self:GetCreatureNearestCoords(entry, self:GetX(), self:GetY(), self:GetZ(), self:GetO())) 95 function CREATURE:IsCasting() 96 return self:GetCurrentSpell() ~= nil 86 97 end 87 function CREATURE:FaceUnit(tar) 88 if (type(tar) == "userdata" and tar:GetObjectType() == "Unit") 89 self:SetFacing(self:CalcRadAngle(self:GetX(), self:GetY(), tar:GetX(), tar:GetY())) 90 return true 91 else 92 return nil 93 end 98 function CREATURE:SetCreator(creator) 99 self:SetUInt64Value(LCF.UNIT_FIELD_CREATEDBY,creator:GetGUID()) 94 100 end 101 function CREATURE:GetCreator() 102 local creator_guid = self:GetUInt64Value(LCF.UNIT_FIELD_CREATEDBY) 103 if(creator_guid == nil) then 104 creator_guid = self:GetUInt64Value(LCF.UNIT_FIELD_SUMMONEDBY) 105 end 106 return self:GetObject(creator_guid) 107 end 108 function CREATURE:GetLocalCreature(entry) 109 local x,y,z = self:GetLocation() 110 local crc = self:GetCreatureNearestCoords(x,y,z,entry) 111 return crc 112 end 113 function CREATURE:GetLocalGameObject(entry) 114 local x,y,z = self:GetLocation() 115 local go = self:GetGameObjectNearestCoords(x,y,z,entry) 116 return go 117 end -
Trunk/lua/Misc/0LCF_Includes/LCF_Extra.lua
r1174 r1207 110 110 if(type(delay) ~= "number") then error("Invalid argument #2, expected number got ->"..type(delay)) end 111 111 if(type(repeats) ~= "number") then error("Invalid argument #3, expected number got->"..type(repeats)) end 112 assert(type(arg) == "table","Inter val error, arg is not a table.")112 assert(type(arg) == "table","Internal error, arg is not a table.") 113 113 if(delay <= 0) then error("Invalid argument #2, delay must be greater than 0.") end 114 local struct = {evt_typ,{func,delay, interval,repeats,arg} }114 local struct = {evt_typ,{func,delay,repeats,repeats,arg} } 115 115 table.insert(self.call_backs,struct) 116 116 end … … 149 149 return function(...) return method(method_table,unpack(arg)) end 150 150 end 151 152 153 RegisterServerHook(15,"LCF:HandleOnZone") 154 RegisterServerHook(26,"LCF:HandleOnAreaTrigger") 151 RegisterServerHook(15,LCF:BindMethod(LCF.HandleOnZone,LCF)) 152 RegisterServerHook(26,LCF:BindMethod(LCF.HandleOnAreaTrigger,LCF)) 155 153 RegisterTimedEvent("LCF:UpdateCallBacks",100,0) -
Trunk/lua/Misc/0LCF_Includes/LCF_Gameobject.lua
r1174 r1207 62 62 LCF:RemoveLuaEvent(tostring(self),func) 63 63 end 64 function GAMEOBJECT:SetCreator(creator) 65 local guid = creator:GetGUID() 66 self:SetUInt64Value(LCF.OBJECT_FIELD_CREATED_BY,guid) 67 end 68 function GAMEOBJECT:GetCreator() 69 local guid = self:GetUInt64Value(LCF.OBJECT_FIELD_CREATED_BY) 70 return self:GetObject(guid) 71 end 72 function GAMEOBJECT:GetLocalCreature(entry) 73 local x,y,z = self:GetLocation() 74 local crc = self:GetCreatureNearestCoords(x,y,z,entry) 75 return crc 76 end 77 function GAMEOBJECT:GetLocalGameObject(entry) 78 local x,y,z = self:GetLocation() 79 local go = self:GetGameObjectNearestCoords(x,y,z,entry) 80 return go 81 end 82 function GAMEOBJECT:GetCreator() 83 local creator_guid = self:GetUInt64Value(LCF.UNIT_FIELD_CREATEDBY) 84 if(creator_guid == nil) then 85 creator_guid = self:GetUInt64Value(LCF.UNIT_FIELD_SUMMONEDBY) 86 end 87 return self:GetObject(creator_guid) 88 end -
Trunk/lua/Misc/0LCF_Includes/LCF_Player.lua
r1190 r1207 66 66 LCF:RemoveLuaEvent(tostring(self),func) 67 67 end 68 function PLAYER: GetNearestUnitWithEntry(entry)69 return (self:GetCreatureNearestCoords(entry, self:GetX(), self:GetY(), self:GetZ(), self:GetO())) 68 function PLAYER:IsCasting() 69 return player:GetCurrentSpell() ~= nil 70 70 end 71 function PLAYER:GetLocalCreature(entry) 72 local x,y,z = self:GetLocation() 73 local crc = self:GetCreatureNearestCoords(x,y,z,entry) 74 return crc 75 end 76 function PLAYER:GetLocalGameObject(entry) 77 local x,y,z = self:GetLocation() 78 local go = self:GetGameObjectNearestCoords(x,y,z,entry) 79 return go 80 end -
Trunk/src/LuaEngine/FunctionTables.h
r1190 r1207 524 524 { "GetSpawnLocation", &luaUnit::GetSpawnLocation }, 525 525 { "GetPlayerMovementFlags", &luaUnit::GetPlayerMovementFlags}, 526 { "GetObject", &luaUnit::GetObject }, 526 527 { NULL, NULL }, 527 528 }; … … 623 624 { "GetLocation", &luaGameObject::GetLocation }, 624 625 { "GetSpawnLocation", &luaGameObject::GetSpawnLocation }, 626 { "GetObject", &luaGameObject::GetObject }, 625 627 { NULL, NULL }, 626 628 }; -
Trunk/src/LuaEngine/GameobjectFunctions.h
r1174 r1207 1073 1073 return 4; 1074 1074 } 1075 int GetObject(lua_State * L, GameObject * ptr) 1076 { 1077 TEST_GO(); 1078 uint64 guid = CHECK_GUID(L,1); 1079 Object * obj = ptr->GetMapMgr()->_GetObject(guid); 1080 if(obj != NULL && obj->IsUnit() ) 1081 PUSH_UNIT(L,obj); 1082 else if(obj != NULL && obj->IsGameObject() ) 1083 PUSH_GO(L,obj); 1084 else 1085 lua_pushnil(L); 1086 return 1; 1087 } 1075 1088 } 1076 1089 #endif -
Trunk/src/LuaEngine/LUAEngine.cpp
r1206 r1207 236 236 void LuaEngine::BeginCall(uint16 fReference) 237 237 { 238 if(fReference > 0) 239 { 240 lua_settop(lu,0); //stack should be empty 241 lua_rawgeti(lu,LUA_REGISTRYINDEX,fReference); 242 if(!lua_isfunction(lu,-1) ) 243 luaL_error(lu,"Attempted to call invalid function. \n"); 244 } 238 lua_settop(lu,0); //stack should be empty 239 lua_getref(lu,fReference); 245 240 } 246 241 bool LuaEngine::ExecuteCall(uint8 params, uint8 res) … … 556 551 } 557 552 } 558 if(functionRef )553 if(functionRef > 0) 559 554 sLuaMgr.RegisterEvent(REGTYPE_SERVHOOK,0,ev,functionRef); 560 555 return 0; … … 627 622 } 628 623 } 629 if(functionRef )624 if(functionRef > 0) 630 625 sLuaMgr.RegisterEvent(REGTYPE_DUMMYSPELL,entry,0,functionRef); 631 626 return 0; … … 692 687 } 693 688 } 694 if(functionRef )689 if(functionRef > 0) 695 690 sLuaMgr.RegisterEvent(REGTYPE_UNIT,entry,ev,functionRef); 696 691 return 0; … … 757 752 } 758 753 } 759 if(functionRef )754 if(functionRef > 0) 760 755 sLuaMgr.RegisterEvent(REGTYPE_QUEST,entry,ev,functionRef); 761 756 return 0; … … 822 817 } 823 818 } 824 if(functionRef )819 if(functionRef > 0) 825 820 sLuaMgr.RegisterEvent(REGTYPE_GO,entry,ev,functionRef); 826 821 return 0; … … 887 882 } 888 883 } 889 if(functionRef )884 if(functionRef > 0) 890 885 sLuaMgr.RegisterEvent(REGTYPE_UNIT_GOSSIP,entry,ev,functionRef); 891 886 return 0; … … 951 946 } 952 947 } 953 if(functionRef )948 if(functionRef > 0) 954 949 sLuaMgr.RegisterEvent(REGTYPE_ITEM_GOSSIP,entry,ev,functionRef); 955 950 return 0; … … 1012 1007 } 1013 1008 } 1014 if(functionRef )1009 if(functionRef > 0) 1015 1010 sLuaMgr.RegisterEvent(REGTYPE_GO_GOSSIP,entry,ev,functionRef); 1016 1011 return 0; … … 2540 2535 } 2541 2536 else 2537 { 2538 if(bind->m_functionReferences[evt] > 0) 2539 lua_unref(lu,bind->m_functionReferences[evt]); 2542 2540 bind->m_functionReferences[evt] = functionRef; 2541 } 2543 2542 } 2544 2543 }break; … … 2554 2553 } 2555 2554 else 2555 { 2556 if(bind->m_functionReferences[evt] > 0) 2557 lua_unref(lu,bind->m_functionReferences[evt]); 2556 2558 bind->m_functionReferences[evt] = functionRef; 2559 } 2557 2560 } 2558 2561 }break; … … 2568 2571 } 2569 2572 else 2573 { 2574 if(bind->m_functionReferences[evt] > 0) 2575 lua_unref(lu,bind->m_functionReferences[evt]); 2570 2576 bind->m_functionReferences[evt] = functionRef; 2577 } 2571 2578 } 2572 2579 }break; … … 2592 2599 } 2593 2600 else 2601 { 2602 if(bind->m_functionReferences[evt] > 0) 2603 lua_unref(lu,bind->m_functionReferences[evt]); 2594 2604 bind->m_functionReferences[evt] = functionRef; 2605 } 2595 2606 } 2596 2607 }break; … … 2606 2617 } 2607 2618 else 2619 { 2620 if(bind->m_functionReferences[evt] > 0) 2621 lua_unref(lu,bind->m_functionReferences[evt]); 2608 2622 bind->m_functionReferences[evt] = functionRef; 2623 } 2609 2624 } 2610 2625 }break; … … 2620 2635 } 2621 2636 else 2637 { 2638 if(bind->m_functionReferences[evt] > 0) 2639 lua_unref(lu,bind->m_functionReferences[evt]); 2622 2640 bind->m_functionReferences[evt] = functionRef; 2641 } 2623 2642 } 2624 2643 }break; … … 2631 2650 RemoveTimedEvents(lu); 2632 2651 // clean up the engine of any existing defined variables 2652 for(UnitBindingMap::iterator itr = m_unitBinding.begin(); itr != m_unitBinding.end(); ++itr) 2653 { 2654 for(int i = 0; i < CREATURE_EVENT_COUNT; ++i) 2655 { 2656 if(itr->second.m_functionReferences[i] > 0) 2657 lua_unref(lu,itr->second.m_functionReferences[i]); 2658 } 2659 } 2633 2660 m_unitBinding.clear(); 2661 for(GameObjectBindingMap::iterator itr = m_gameobjectBinding.begin(); itr != m_gameobjectBinding.end(); ++itr) 2662 { 2663 for(int i = 0; i < GAMEOBJECT_EVENT_COUNT; ++i) 2664 { 2665 if(itr->second.m_functionReferences[i] > 0) 2666 lua_unref(lu,itr->second.m_functionReferences[i]); 2667 } 2668 } 2634 2669 m_gameobjectBinding.clear(); 2670 for(QuestBindingMap::iterator itr = m_questBinding.begin(); itr != m_questBinding.end(); ++itr) 2671 { 2672 for(int i = 0; i < QUEST_EVENT_COUNT; ++i) 2673 { 2674 if(itr->second.m_functionReferences[i] > 0) 2675 lua_unref(lu,itr->second.m_functionReferences[i]); 2676 } 2677 } 2635 2678 m_questBinding.clear(); 2679 for(GossipUnitScriptsBindingMap::iterator itr = m_unit_gossipBinding.begin(); itr != m_unit_gossipBinding.end(); ++itr) 2680 { 2681 for(int i = 0; i < GOSSIP_EVENT_COUNT; ++i) 2682 { 2683 if(itr->second.m_functionReferences[i] > 0) 2684 lua_unref(lu,itr->second.m_functionReferences[i]); 2685 } 2686 } 2636 2687 m_unit_gossipBinding.clear(); 2688 for(GossipItemScriptsBindingMap::iterator itr = m_item_gossipBinding.begin(); itr != m_item_gossipBinding.end(); ++itr) 2689 { 2690 for(int i = 0; i < GOSSIP_EVENT_COUNT; ++i) 2691 { 2692 if(itr->second.m_functionReferences[i] > 0) 2693 lua_unref(lu,itr->second.m_functionReferences[i]); 2694 } 2695 } 2637 2696 m_item_gossipBinding.clear(); 2697 for(GossipGOScriptsBindingMap::iterator itr = m_go_gossipBinding.begin(); itr != m_go_gossipBinding.end(); ++itr) 2698 { 2699 for(int i = 0; i < GOSSIP_EVENT_COUNT; ++i) 2700 { 2701 if(itr->second.m_functionReferences[i] > 0) 2702 lua_unref(lu,itr->second.m_functionReferences[i]); 2703 } 2704 } 2638 2705 m_go_gossipBinding.clear(); 2639 2706 //Serv hooks : had forgotten these. … … 2641 2708 { 2642 2709 vector<uint16> & next = EventAsToFuncName[i]; 2710 for(vector<uint16>::iterator itr = next.begin(); itr != next.end(); ++itr) 2711 lua_unref(lu,(*itr)); 2643 2712 next.clear(); 2644 2713 } 2714 for(map<uint32,uint16>::iterator itr = m_luaDummySpells.begin(); itr != m_luaDummySpells.end(); ++itr) 2715 lua_unref(lu,itr->second); 2645 2716 m_luaDummySpells.clear(); 2717 for(set<int>::iterator itr = m_pendingThreads.begin(); itr != m_pendingThreads.end(); ++itr) 2718 lua_unref(lu,(*itr)); 2646 2719 m_pendingThreads.clear(); 2647 2720 -
Trunk/src/LuaEngine/UnitFunctions.h
r1205 r1207 886 886 int flag = luaL_checkint( L, 1 ); 887 887 Player* ret = NULL; 888 vector<Player*> players; 888 889 switch( flag ) 889 890 { … … 907 908 908 909 { 909 uint32 count = 0;910 910 for(set< Object* >::iterator itr = ptr->GetInRangePlayerSetBegin(); itr != ptr->GetInRangePlayerSetEnd(); ++itr) 911 911 { 912 912 Player* obj = TO_PLAYER(*itr); 913 913 if (obj && obj->CalcDistance(obj,ptr)<=8) 914 ++count;914 players.push_back(obj); 915 915 } 916 if (count) 917 { 918 uint32 r = RandomUInt(count-1); 919 count=0; 920 for(set< Object* >::iterator itr = ptr->GetInRangePlayerSetBegin(); itr != ptr->GetInRangePlayerSetEnd(); ++itr) 921 { 922 Player* obj = TO_PLAYER(*itr); 923 if (obj && obj->CalcDistance(obj,ptr)<=8 && count==r) 924 { 925 ret=obj; 926 break; 927 } 928 ++count; 929 } 930 } 916 ret = players[RandomUInt(players.size()-1)]; 931 917 } 932 918 break; 933 919 case RANDOM_IN_MIDRANGE: 934 920 { 935 uint32 count = 0;936 921 for(set< Object* >::iterator itr = ptr->GetInRangePlayerSetBegin(); itr != ptr->GetInRangePlayerSetEnd(); ++itr) 937 922 { 938 923 Player* obj = TO_PLAYER(*itr); 939 if (!obj)940 continue;941 924 float distance = obj->CalcDistance(obj,ptr); 942 925 if (distance<20 && distance>8) 943 ++count;926 players.push_back(obj); 944 927 } 945 if (count) 946 { 947 uint32 r = RandomUInt(count-1); 948 count=0; 949 for(set< Object* >::iterator itr = ptr->GetInRangePlayerSetBegin(); itr != ptr->GetInRangePlayerSetEnd(); ++itr) 950 { 951 Player* obj = TO_PLAYER(*itr); 952 if (!obj) 953 continue; 954 float distance = obj->CalcDistance(obj,ptr); 955 if (distance<20 && distance>8 && count==r) 956 { 957 ret=obj; 958 break; 959 } 960 ++count; 961 } 962 } 928 ret = players[RandomUInt(players.size()-1)]; 963 929 } 964 930 break; 965 931 case RANDOM_IN_LONGRANGE: 966 932 { 967 uint32 count = 0;968 933 for(set< Object* >::iterator itr = ptr->GetInRangePlayerSetBegin(); itr != ptr->GetInRangePlayerSetEnd(); ++itr) 969 934 { 970 935 Player* obj = TO_PLAYER(*itr); 971 936 if (obj && obj->CalcDistance(obj,ptr)>=20) 972 ++count;937 players.push_back(obj); 973 938 } 974 if (count) 975 { 976 uint32 r = RandomUInt(count-1); 977 count=0; 978 for(set< Object* >::iterator itr = ptr->GetInRangePlayerSetBegin(); itr != ptr->GetInRangePlayerSetEnd(); ++itr) 979 { 980 Player* obj = TO_PLAYER(*itr); 981 if (obj && obj->CalcDistance(obj,ptr)>=20 && count==r) 982 { 983 ret=obj; 984 break; 985 } 986 ++count; 987 } 988 } 939 ret = players[RandomUInt(players.size()-1)]; 989 940 } 990 941 break; 991 942 case RANDOM_WITH_MANA: 992 943 { 993 uint32 count = 0;994 944 for(set< Object* >::iterator itr = ptr->GetInRangePlayerSetBegin(); itr != ptr->GetInRangePlayerSetEnd(); ++itr) 995 945 { 996 946 Player* obj = TO_PLAYER(*itr); 997 947 if (obj && obj->GetPowerType() == POWER_TYPE_MANA) 998 ++count;948 players.push_back(obj); 999 949 } 1000 if (count) 1001 { 1002 uint32 r = RandomUInt(count-1); 1003 count=0; 1004 for(set< Object* >::iterator itr = ptr->GetInRangePlayerSetBegin(); itr != ptr->GetInRangePlayerSetEnd(); ++itr) 1005 { 1006 Player* obj = TO_PLAYER(*itr); 1007 if (obj && obj->GetPowerType() == POWER_TYPE_MANA && count==r) 1008 { 1009 ret=obj; 1010 break; 1011 } 1012 ++count; 1013 } 1014 } 950 ret = players[RandomUInt(players.size()-1)]; 1015 951 } 1016 952 break; 1017 953 case RANDOM_WITH_ENERGY: 1018 954 { 1019 uint32 count = 0;1020 955 for(set< Object* >::iterator itr = ptr->GetInRangePlayerSetBegin(); itr != ptr->GetInRangePlayerSetEnd(); ++itr) 1021 956 { 1022 957 Player* obj = TO_PLAYER(*itr); 1023 958 if (obj && obj->GetPowerType() == POWER_TYPE_ENERGY) 1024 ++count;959 players.push_back(obj); 1025 960 } 1026 if (count) 1027 { 1028 uint32 r = RandomUInt(count-1); 1029 count=0; 1030 for(set< Object* >::iterator itr = ptr->GetInRangePlayerSetBegin(); itr != ptr->GetInRangePlayerSetEnd(); ++itr) 1031 { 1032 Player* obj = TO_PLAYER(*itr); 1033 if (obj && obj->GetPowerType() == POWER_TYPE_ENERGY && count==r) 1034 { 1035 ret=obj; 1036 break; 1037 } 1038 ++count; 1039 } 1040 } 961 ret = players[RandomUInt(players.size()-1)]; 1041 962 } 1042 963 break; 1043 964 case RANDOM_WITH_RAGE: 1044 965 { 1045 uint32 count = 0;1046 966 for(set< Object* >::iterator itr = ptr->GetInRangePlayerSetBegin(); itr != ptr->GetInRangePlayerSetEnd(); ++itr) 1047 967 { 1048 968 Player* obj = TO_PLAYER(*itr); 1049 969 if (obj && obj->GetPowerType() == POWER_TYPE_RAGE) 1050 ++count;970 players.push_back(obj); 1051 971 } 1052 if (count) 1053 { 1054 uint32 r = RandomUInt(count-1); 1055 count=0; 1056 for(set< Object* >::iterator itr = ptr->GetInRangePlayerSetBegin(); itr != ptr->GetInRangePlayerSetEnd(); ++itr) 1057 { 1058 Player* obj = TO_PLAYER(*itr); 1059 if (obj && obj->GetPowerType() == POWER_TYPE_RAGE && count==r) 1060 { 1061 ret=obj; 1062 break; 1063 } 1064 ++count; 1065 } 1066 } 972 ret = players[RandomUInt(players.size()-1)]; 1067 973 } 1068 974 break; … … 1078 984 Player* obj = TO_PLAYER(*itr); 1079 985 if (obj != mt) 1080 ++count;986 players.push_back(obj); 1081 987 } 1082 if (count) 1083 { 1084 uint32 r = RandomUInt(count-1); 1085 count=0; 1086 for(set< Object* >::iterator itr = ptr->GetInRangePlayerSetBegin(); itr != ptr->GetInRangePlayerSetEnd(); ++itr) 1087 { 1088 Player* obj = TO_PLAYER(*itr); 1089 if (obj && obj != mt && count==r) 1090 { 1091 ret=obj; 1092 break; 1093 } 1094 ++count; 1095 } 1096 } 988 ret = players[RandomUInt(players.size()-1)]; 1097 989 } 1098 990 break; … … 1108 1000 int GetRandomFriend(lua_State * L, Unit * ptr) 1109 1001 { 1110 if(!ptr) 1111 return 0; 1002 TEST_UNITPLAYER(); 1112 1003 1113 1004 Unit * ret=NULL; 1114 1005 uint32 count = 0; 1006 vector<Object*> allies; 1115 1007 1116 1008 for(set<Object*>::iterator itr = ptr->GetInRangeSetBegin(); itr != ptr->GetInRangeSetEnd(); ++itr) … … 1118 1010 Object* obj = TO_OBJECT(*itr); 1119 1011 if (obj->IsUnit() && isFriendly(obj,ptr)) 1120 ++count; 1121 } 1122 1123 if (count) 1124 { 1125 uint32 r = RandomUInt(count-1); 1126 count=0; 1127 for(set<Object*>::iterator itr = ptr->GetInRangeSetBegin(); itr != ptr->GetInRangeSetEnd(); ++itr) 1128 { 1129 Object* obj = TO_OBJECT(*itr); 1130 if (obj->IsUnit() && isFriendly(obj,ptr) && count==r) 1131 { 1132 ret= TO_UNIT(obj); 1133 break; 1134 } 1135 ++count; 1136 } 1137 } 1138 if(ret==NULL) 1139 lua_pushnil(L); 1140 else 1141 PUSH_UNIT(L,ret); 1012 allies.push_back(obj); 1013 } 1014 PUSH_UNIT(L,allies[RandomUInt(allies.size()-1)]); 1142 1015 return 1; 1143 1016 } 1144 1017 int GetRandomEnemy(lua_State * L, Unit * ptr) 1145 1018 { 1146 if(!ptr) 1147 return 0; 1019 TEST_UNITPLAYER(); 1148 1020 1149 1021 Unit * ret=NULL; 1150 1022 uint32 count = 0; 1023 vector<Object*> enemies; 1151 1024 1152 1025 for(set<Object*>::iterator itr = ptr->GetInRangeSetBegin(); itr != ptr->GetInRangeSetEnd(); ++itr) … … 1154 1027 Object* obj = TO_OBJECT(*itr); 1155 1028 if (obj->IsUnit() && !isFriendly(obj,ptr)) 1156 ++count; 1157 } 1158 1159 if (count) 1160 { 1161 uint32 r = RandomUInt(count-1); 1162 count=0; 1163 for(set<Object*>::iterator itr = ptr->GetInRangeSetBegin(); itr != ptr->GetInRangeSetEnd(); ++itr) 1164 { 1165 Object* obj = TO_OBJECT(*itr); 1166 if (obj->IsUnit() && !isFriendly(obj,ptr) && count==r) 1167 { 1168 ret= TO_UNIT(obj); 1169 break; 1170 } 1171 ++count; 1172 } 1173 } 1174 if(ret==NULL) 1175 lua_pushnil(L); 1176 else 1177 PUSH_UNIT(L,ret); 1029 enemies.push_back(obj); 1030 } 1031 PUSH_UNIT(L,enemies[RandomUInt(enemies.size()-1)]); 1178 1032 return 1; 1179 1033 } … … 1189 1043 int RemoveAura(lua_State * L, Unit * ptr) 1190 1044 { 1191 if (!ptr) return 0;1045 TEST_UNITPLAYER() 1192 1046 int auraid = luaL_checkint(L,1); 1193 1047 ptr->RemoveAura(auraid); … … 1197 1051 int CanAttack(lua_State * L, Unit * ptr) 1198 1052 { 1053 TEST_UNITPLAYER_RET(); 1199 1054 Unit * target = CHECK_UNIT(L,1); 1200 if (! ptr || !target) return 0;1055 if (!target) return 0; 1201 1056 if (isAttackable(ptr, target)) 1202 1057 lua_pushboolean(L, 1); … … 1208 1063 int PlaySoundToSet(lua_State * L, Unit * ptr) 1209 1064 { 1210 if (!ptr) return 0;1065 TEST_UNITPLAYER(); 1211 1066 int soundid = luaL_checkint(L,1); 1212 1067 ptr->PlaySoundToSet(soundid); … … 1216 1071 int PlaySoundToPlayer(lua_State * L, Unit * ptr) 1217 1072 { 1073 TEST_PLAYER(); 1218 1074 int soundid = luaL_checkint(L,1); 1219 1075 Player* plr = TO_PLAYER(ptr); 1220 if (!plr) return 0;1221 1076 WorldPacket data; 1222 1077 data.Initialize(SMSG_PLAY_OBJECT_SOUND); … … 5998 5853 return 4; 5999 5854 } 5855 int GetObject(lua_State * L, Unit * ptr) 5856 { 5857 TEST_UNIT(); 5858 uint64 guid = CHECK_GUID(L,1); 5859 Object * obj = ptr->GetMapMgr()->_GetObject(guid); 5860 if(obj != NULL && obj->IsUnit() ) 5861 PUSH_UNIT(L,obj); 5862 else if(obj != NULL && obj->IsGameObject() ) 5863 PUSH_GO(L,obj); 5864 else 5865 lua_pushnil(L); 5866 return 1; 5867 } 6000 5868 } 6001 5869 #endif
![(please configure the [header_logo] section in trac.ini)](/trac/arcscripts/chrome/site/your_project_logo.png)