Here's what I came up with for the lua function basically a copy and paste of SpellAttack.
Code: Select all
int EQ2Emu_lua_SpellHeal(lua_State* state){
if(!lua_interface)
return 0;
Spawn* target = lua_interface->GetSpawn(state);
LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
if(!luaspell)
return 0;
Spawn* caster = luaspell->caster;
sint32 type = 0; //HEAL_PACKET_TYPE_SIMPLE_HEAL? have to figure out heal packet types
sint32 heal_type = lua_interface->GetInt32Value(state, 2);//ward heal ect
int32 min_heal = lua_interface->GetInt32Value(state, 3);
int32 max_heal = lua_interface->GetInt32Value(state, 4);
lua_interface->ResetFunctionStack(state);
if(caster && caster->IsEntity()){
bool success = false;
luaspell->resisted = false;
if (luaspell->targets.size() > 0) {
for (int32 i = 0; i < luaspell->targets.size(); i++) {
if (luaspell->targets[i]) {
float distance = caster->GetDistance(luaspell->targets[i], true);
distance -= caster->appearance.pos.collision_radius/10;
distance -= luaspell->targets[i]->appearance.pos.collision_radius/10;
((Entity*)caster)->SpellHeal(luaspell->targets[i], distance, luaspell, type, heal_type, min_heal, max_heal);
}
}
success = true;
}
else if (target) {
float distance = caster->GetDistance(target, true);
distance -= caster->appearance.pos.collision_radius/10;
distance -= target->appearance.pos.collision_radius/10;
if (((Entity*)caster)->SpellHeal(target, distance, luaspell, type, 0, min_heal, max_heal))
success = true;
}
if (success) {
Spell* spell = luaspell->spell;
if(caster->GetZone())
caster->GetZone()->TriggerCharSheetTimer();
}
}
return 0;
}
And here's SpellHeal in the combat code
Code: Select all
bool Entity::SpellHeal(Spawn* target, float distance, LuaSpell* luaspell, int8 type, int8 damage_type, int32 low_heal, int32 high_heal){
if(!target || !luaspell || !luaspell->spell || distance > luaspell->spell->GetSpellData()->range || IsMezzedOrStunned() || IsStifled())
return false;
/*Spell* spell = luaspell->spell;
Skill* skill = 0;
skill = master_skill_list.GetSkill(spell->GetSpellData()->mastery_skill;*/
int32 heal_amt = 0;
if(low_heal > high_heal)
heal_amt = low_heal;
if(low_heal == high_heal)
heal_amt = low_heal;
else
heal_amt = MakeRandomInt(low_heal, high_heal);
if (heal_amt > 0){
//int32 base_roll = heal_amt;
//potency mod
heal_amt += (heal_amt * (stats[ITEM_STAT_POTENCY] / 100 + 1));
//primary stat mod, insert forula here when done
//heal_amt += base_roll * (GetPrimaryStat()
//Ability Modifier can only be up to half of base roll + potency and primary stat bonus
heal_amt += (int32)min(info_struct.ability_modifier, (float)(heal_amt / 2));
}
else
return false;
// Crit Roll
float chance = max((float)0, info_struct.crit_chance);
if (MakeRandomFloat(0, 100) <= chance) {
//Apply total crit multiplier with crit bonus
heal_amt *= info_struct.crit_bonus / 100 + 1.3;
/* Change packet type to crit
if (type == DAMAGE_PACKET_TYPE_SIMPLE_DAMAGE)
type = DAMAGE_PACKET_TYPE_SIMPLE_CRIT_DMG;
else if (type == DAMAGE_PACKET_TYPE_SPELL_DAMAGE)
type = DAMAGE_PACKET_TYPE_SPELL_CRIT_DMG;*/
}
if (target->GetHP() + heal_amt > target->GetTotalHP())
target->SetHP(target->GetTotalHP());
else
target->SetHP(target->GetHP() + heal_amt);
target->GetZone()->TriggerCharSheetTimer();
return true;
}
Have to figure out the heal packet format before I can get heals to show up in the combat window (I assume the heal numbers show up too). Not going to commit until jab checks it out as I don't understand all of the spell code
Syntax is SpellHeal(Target, HealType, MinHeal, MaxHeal)
Obviously healtypes aren't defined yet so it's not really used for now, will be for wards ect eventually. The type variables should eventually be crit heal, normal heal ect.
Side note once heal packets are finished should look at a separate function for taunts and threat packets as well. Almost thinking we should have different damage functions for (Auto attack, taunts, heals, spell attacks), for the sake of performance and simplicity reading the code. Since we call them from different functions anyway.