mirror of
https://github.com/ErikasKontenis/SabrehavenServer.git
synced 2025-05-07 12:19:20 +02:00
finish knight melee damage calculation todo hits with paladin
This commit is contained in:
parent
8de51cb8ea
commit
b0b93edcb4
139
data/talkactions/scripts/melee_damage.lua
Normal file
139
data/talkactions/scripts/melee_damage.lua
Normal file
@ -0,0 +1,139 @@
|
|||||||
|
local weaponSkillsConfig = {
|
||||||
|
[WEAPON_SWORD] = SKILL_SWORD,
|
||||||
|
[WEAPON_CLUB] = SKILL_CLUB,
|
||||||
|
[WEAPON_AXE] = SKILL_AXE,
|
||||||
|
[WEAPON_DISTANCE] = SKILL_DISTANCE
|
||||||
|
}
|
||||||
|
|
||||||
|
local function getWeapon(player)
|
||||||
|
local itemLeft = player:getSlotItem(CONST_SLOT_LEFT)
|
||||||
|
if itemLeft and itemLeft:getType():getWeaponType() ~= WEAPON_NONE and itemLeft:getType():getWeaponType() ~= WEAPON_SHIELD and itemLeft:getType():getWeaponType() ~= WEAPON_AMMO then
|
||||||
|
return itemLeft
|
||||||
|
end
|
||||||
|
|
||||||
|
local itemRight = player:getSlotItem(CONST_SLOT_RIGHT)
|
||||||
|
if itemRight and itemRight:getType():getWeaponType() ~= WEAPON_NONE and itemRight:getType():getWeaponType() ~= WEAPON_SHIELD and itemRight:getType():getWeaponType() ~= WEAPON_AMMO then
|
||||||
|
return itemRight
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function getDamageFormula(attack, attackSkill, fightMode)
|
||||||
|
local damage = attack
|
||||||
|
if fightMode == FIGHTMODE_ATTACK then
|
||||||
|
damage = math.floor(damage + 2 * damage / 10)
|
||||||
|
elseif fightMode == FIGHTMODE_DEFENSE then
|
||||||
|
damage = math.floor(damage - 4 * damage / 10)
|
||||||
|
end
|
||||||
|
|
||||||
|
local formula = math.floor((5 * (attackSkill) + 50) * damage)
|
||||||
|
return formula
|
||||||
|
end
|
||||||
|
|
||||||
|
local function getDamage(attack, attackSkill, fightMode, random1, random2)
|
||||||
|
local formula = getDamageFormula(attack, attackSkill, fightMode)
|
||||||
|
local randResult = math.floor(random1 % 100);
|
||||||
|
local damage = -math.floor((math.ceil(formula * ((random2 % 100 + randResult) / 2) / 10000.)));
|
||||||
|
return damage
|
||||||
|
end
|
||||||
|
|
||||||
|
local function getMinDamage(attack, attackSkill, fightMode)
|
||||||
|
local formula = getDamageFormula(attack, attackSkill, fightMode)
|
||||||
|
local damage = -math.floor((math.ceil(formula * (0 / 2) / 10000.)));
|
||||||
|
return damage
|
||||||
|
end
|
||||||
|
|
||||||
|
local function getMaxDamage(attack, attackSkill, fightMode)
|
||||||
|
local formula = getDamageFormula(attack, attackSkill, fightMode)
|
||||||
|
local damage = -math.floor((math.ceil(formula * (198 / 2) / 10000.)));
|
||||||
|
return damage
|
||||||
|
end
|
||||||
|
|
||||||
|
local function setVocationDamageIncrease(vocationId, damage)
|
||||||
|
local knightCloseAttackDamageIncreasePercent = configManager.getNumber(configKeys.KNIGHT_CLOSE_ATTACK_DAMAGE_INCREASE_PERCENT)
|
||||||
|
if knightCloseAttackDamageIncreasePercent ~= -1 then
|
||||||
|
damage = math.floor(damage + damage * knightCloseAttackDamageIncreasePercent / 100);
|
||||||
|
end
|
||||||
|
|
||||||
|
return damage
|
||||||
|
end
|
||||||
|
|
||||||
|
local function getDefense(creature, random1, random2)
|
||||||
|
local totalDefense = creature:getType():getDefense() + 1
|
||||||
|
local defenseSkill = creature:getType():getSkill()
|
||||||
|
|
||||||
|
local formula = math.floor((5 * (defenseSkill) + 50) * totalDefense)
|
||||||
|
local randresult = math.floor(random1 % 100)
|
||||||
|
|
||||||
|
return math.floor(formula * ((random2 % 100 + randresult) / 2) / 10000.)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function rshift(x, by)
|
||||||
|
return math.floor(x / 2 ^ by)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function getArmor(creature, rand)
|
||||||
|
local armor = creature:getType():getArmor()
|
||||||
|
if armor > 1 then
|
||||||
|
return rand % rshift(armor, 1) + rshift(armor, 1);
|
||||||
|
end
|
||||||
|
|
||||||
|
return armor
|
||||||
|
end
|
||||||
|
|
||||||
|
local function setDamageBlock(creature, damage, random1, random2, randomArmor)
|
||||||
|
if bit.band(creature:getType():getCombatImmunities(), COMBAT_PHYSICALDAMAGE) == COMBAT_PHYSICALDAMAGE then
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
|
||||||
|
damage = damage + getDefense(creature, random1, random2)
|
||||||
|
|
||||||
|
if damage >= 0 then
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
|
||||||
|
if damage < 0 then
|
||||||
|
print (getArmor(creature, randomArmor))
|
||||||
|
damage = damage + getArmor(creature, randomArmor)
|
||||||
|
if damage >= 0 then
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return damage
|
||||||
|
end
|
||||||
|
|
||||||
|
function onSay(player, words, param)
|
||||||
|
local split = param:split(",")
|
||||||
|
if split[3] == nil then
|
||||||
|
--player:sendCancelMessage("Insufficient parameters [(exp,skill,loot,magic),percentage,hours].")
|
||||||
|
--return false
|
||||||
|
end
|
||||||
|
|
||||||
|
local creature = Creature("Troll")
|
||||||
|
if creature == nil then
|
||||||
|
player:sendCancelMessage("The monster does not exist.")
|
||||||
|
end
|
||||||
|
|
||||||
|
local skillType = SKILL_FIST
|
||||||
|
local attack = 7
|
||||||
|
local weapon = getWeapon(player)
|
||||||
|
if weapon ~= nil then
|
||||||
|
attack = weapon:getType():getAttack()
|
||||||
|
skillType = weaponSkillsConfig[weapon:getType():getWeaponType()]
|
||||||
|
end
|
||||||
|
|
||||||
|
local damage = setDamageBlock(creature, setVocationDamageIncrease(player:getVocation():getId(), getDamage(attack, player:getSkillLevel(skillType), FIGHTMODE_ATTACK, os.rand(), os.rand())), os.rand(), os.rand(), os.rand())
|
||||||
|
local minDamage = setDamageBlock(creature, setVocationDamageIncrease(player:getVocation():getId(), getDamage(attack, player:getSkillLevel(skillType), FIGHTMODE_ATTACK, 0, 0)), 99, 99, rshift(creature:getType():getArmor(), 1) + 1)
|
||||||
|
local maxDamage = setDamageBlock(creature, setVocationDamageIncrease(player:getVocation():getId(), getDamage(attack, player:getSkillLevel(skillType), FIGHTMODE_ATTACK, 99, 99)), 0, 0, 0)
|
||||||
|
|
||||||
|
print ("TotalDamage:" .. damage)
|
||||||
|
print ("MinDamage:" .. minDamage)
|
||||||
|
print ("MaxDamage:" .. maxDamage)
|
||||||
|
--print (weapon:getType():getAttack())
|
||||||
|
--print (shield:getName())
|
||||||
|
local message = ""
|
||||||
|
message = message .. "Offensive Fighting\n"
|
||||||
|
message = message .. "- Daily kills for red skull " .. 123 .. "\n"
|
||||||
|
--player:showTextDialog(1998, message, false)
|
||||||
|
return false
|
||||||
|
end
|
@ -56,6 +56,7 @@
|
|||||||
<talkaction words="!serverinfo" script="serverinfo.lua"/>
|
<talkaction words="!serverinfo" script="serverinfo.lua"/>
|
||||||
<talkaction words="!share" script="experienceshare.lua"/>
|
<talkaction words="!share" script="experienceshare.lua"/>
|
||||||
<talkaction words="!shop" script="znoteshop.lua"/>
|
<talkaction words="!shop" script="znoteshop.lua"/>
|
||||||
|
<talkaction words="!meleedamage" script="melee_damage.lua"/>
|
||||||
<talkaction words="469" script="469.lua"/>
|
<talkaction words="469" script="469.lua"/>
|
||||||
|
|
||||||
<!-- test talkactions -->
|
<!-- test talkactions -->
|
||||||
|
@ -1684,6 +1684,9 @@ void LuaScriptInterface::registerFunctions()
|
|||||||
registerEnumIn("configKeys", ConfigManager::BLOCK_HEIGHT)
|
registerEnumIn("configKeys", ConfigManager::BLOCK_HEIGHT)
|
||||||
registerEnumIn("configKeys", ConfigManager::DROP_ITEMS)
|
registerEnumIn("configKeys", ConfigManager::DROP_ITEMS)
|
||||||
registerEnumIn("configKeys", ConfigManager::CLIENT_VERSION)
|
registerEnumIn("configKeys", ConfigManager::CLIENT_VERSION)
|
||||||
|
|
||||||
|
// random
|
||||||
|
registerMethod("os", "rand", LuaScriptInterface::luaRandomRand);
|
||||||
|
|
||||||
// os
|
// os
|
||||||
registerMethod("os", "mtime", LuaScriptInterface::luaSystemTime);
|
registerMethod("os", "mtime", LuaScriptInterface::luaSystemTime);
|
||||||
@ -2348,6 +2351,7 @@ void LuaScriptInterface::registerFunctions()
|
|||||||
registerMethod("MonsterType", "getMaxSummons", LuaScriptInterface::luaMonsterTypeGetMaxSummons);
|
registerMethod("MonsterType", "getMaxSummons", LuaScriptInterface::luaMonsterTypeGetMaxSummons);
|
||||||
|
|
||||||
registerMethod("MonsterType", "getArmor", LuaScriptInterface::luaMonsterTypeGetArmor);
|
registerMethod("MonsterType", "getArmor", LuaScriptInterface::luaMonsterTypeGetArmor);
|
||||||
|
registerMethod("MonsterType", "getSkill", LuaScriptInterface::luaMonsterTypeGetSkill);
|
||||||
registerMethod("MonsterType", "getDefense", LuaScriptInterface::luaMonsterTypeGetDefense);
|
registerMethod("MonsterType", "getDefense", LuaScriptInterface::luaMonsterTypeGetDefense);
|
||||||
registerMethod("MonsterType", "getOutfit", LuaScriptInterface::luaMonsterTypeGetOutfit);
|
registerMethod("MonsterType", "getOutfit", LuaScriptInterface::luaMonsterTypeGetOutfit);
|
||||||
registerMethod("MonsterType", "getRace", LuaScriptInterface::luaMonsterTypeGetRace);
|
registerMethod("MonsterType", "getRace", LuaScriptInterface::luaMonsterTypeGetRace);
|
||||||
@ -3888,6 +3892,14 @@ int LuaScriptInterface::luaRawGetMetatable(lua_State* L)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// random
|
||||||
|
int LuaScriptInterface::luaRandomRand(lua_State* L)
|
||||||
|
{
|
||||||
|
// random.rand()
|
||||||
|
lua_pushnumber(L, rand());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
// os
|
// os
|
||||||
int LuaScriptInterface::luaSystemTime(lua_State* L)
|
int LuaScriptInterface::luaSystemTime(lua_State* L)
|
||||||
{
|
{
|
||||||
@ -11225,6 +11237,19 @@ int LuaScriptInterface::luaMonsterTypeGetArmor(lua_State* L)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int LuaScriptInterface::luaMonsterTypeGetSkill(lua_State* L)
|
||||||
|
{
|
||||||
|
// monsterType:getSkill()
|
||||||
|
MonsterType* monsterType = getUserdata<MonsterType>(L, 1);
|
||||||
|
if (monsterType) {
|
||||||
|
lua_pushnumber(L, monsterType->info.skill);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
lua_pushnil(L);
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
int LuaScriptInterface::luaMonsterTypeGetDefense(lua_State* L)
|
int LuaScriptInterface::luaMonsterTypeGetDefense(lua_State* L)
|
||||||
{
|
{
|
||||||
// monsterType:getDefense()
|
// monsterType:getDefense()
|
||||||
|
@ -520,6 +520,9 @@ class LuaScriptInterface
|
|||||||
static int luaIsType(lua_State* L);
|
static int luaIsType(lua_State* L);
|
||||||
static int luaRawGetMetatable(lua_State* L);
|
static int luaRawGetMetatable(lua_State* L);
|
||||||
|
|
||||||
|
// random
|
||||||
|
static int luaRandomRand(lua_State* L);
|
||||||
|
|
||||||
// os
|
// os
|
||||||
static int luaSystemTime(lua_State* L);
|
static int luaSystemTime(lua_State* L);
|
||||||
|
|
||||||
@ -1161,6 +1164,7 @@ class LuaScriptInterface
|
|||||||
static int luaMonsterTypeGetMaxSummons(lua_State* L);
|
static int luaMonsterTypeGetMaxSummons(lua_State* L);
|
||||||
|
|
||||||
static int luaMonsterTypeGetArmor(lua_State* L);
|
static int luaMonsterTypeGetArmor(lua_State* L);
|
||||||
|
static int luaMonsterTypeGetSkill(lua_State* L);
|
||||||
static int luaMonsterTypeGetDefense(lua_State* L);
|
static int luaMonsterTypeGetDefense(lua_State* L);
|
||||||
static int luaMonsterTypeGetOutfit(lua_State* L);
|
static int luaMonsterTypeGetOutfit(lua_State* L);
|
||||||
static int luaMonsterTypeGetRace(lua_State* L);
|
static int luaMonsterTypeGetRace(lua_State* L);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user