Приветствую вас пользователи xgm.guru. Я здесь очень давно не был, но я здесь обучался картостроению. Я бросил варик, и давно им не пользовался, но сегодня решил зайти в редактор(что очень странно) и что-нибудь написать интересное для новичков
Думаю новизной здесь не пахнет, но новичкам будет интересна такая реализация работы с группами.
// by Goodie
include "cj_types.j"
library GExGroup
{
struct ExGroup
{
group CurrentGroup = null;
boolexpr savedFilter = null;
thistype OrderBy(boolexpr filter)
{
this.savedFilter = filter;
return this;
}
void Clean()
{
GroupClear(this.CurrentGroup);
}
thistype SelectRange(float x, float y, float range)
{
GroupEnumUnitsInRange(this.CurrentGroup, x, y, range, this.savedFilter);
return this;
}
thistype DoAction(code clbck)
{
if (CountUnitsInGroup(this.CurrentGroup) <= 0) { return this; }
ForGroup(this.CurrentGroup,clbck);
return this;
}
static thistype create()
{
thistype exGroup = thistype.allocate();
exGroup.CurrentGroup = CreateGroup();
return exGroup;
}
}
}
Ну и конечно же пример использования этой реализации.
Используя какую-то странную реализацию анонимных функций которая компилятор прочитал я закодил вот такую вещь
Используя какую-то странную реализацию анонимных функций которая компилятор прочитал я закодил вот такую вещь
library ExampleSpell initializer Init {
bool FilterForGroup()
{
return GetHeroLevel(GetFilterUnit()) == 5;
}
void Actions()
{
ExGroup Group = ExGroup.create();
Group.OrderBy(Filter(function FilterForGroup))\
.SelectRange(GetUnitX(GetTriggerUnit()),GetUnitY(GetTriggerUnit()),300.0)\
.DoAction(lambda void() {
unit currentUnit = GetEnumUnit();
BJDebugMsg("Name of unit: " + GetUnitName(currentUnit));
DestroyEffect(AddSpecialEffect("Abilities\\Spells\\Human\\ThunderClap\\ThunderClapCaster.mdl",GetUnitX(currentUnit),GetUnitY(currentUnit)));
});
// or
Group.OrderBy(Filter(function FilterForGroup));
Group.SelectRange(GetUnitX(GetTriggerUnit()),GetUnitY(GetTriggerUnit()),300.0);
Group.DoAction(lambda void() {
unit currentUnit = GetEnumUnit();
BJDebugMsg("Name of unit: " + GetUnitName(currentUnit));
DestroyEffect(AddSpecialEffect("Abilities\\Spells\\Human\\ThunderClap\\ThunderClapCaster.mdl",GetUnitX(currentUnit),GetUnitY(currentUnit)));
});
}
void Init()
{
trigger Example_Using = CreateTrigger();
TriggerRegisterAnyUnitEventBJ(Example_Using, EVENT_PLAYER_UNIT_DEATH);
TriggerAddAction(Example_Using, function Actions);
}
}
Как видите, смысл в том, что можно вызывать методы цепочками бесконечно, нну можно и без цепочек.