Skip to content

Commit

Permalink
Merge pull request #4823 from LandSandBoat/tredecim_scythe
Browse files Browse the repository at this point in the history
[core, Lua] Implement Tredecim Scythe
  • Loading branch information
zach2good authored Dec 6, 2023
2 parents 2377b2a + 657b90c commit 23de8d3
Show file tree
Hide file tree
Showing 7 changed files with 148 additions and 0 deletions.
29 changes: 29 additions & 0 deletions scripts/items/tredecim_scythe.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
-----------------------------------
-- ID: 18052
-- Tredecim Scythe
-----------------------------------
local itemObject = {}

itemObject.onItemEquip = function(target, item)
target:addListener('MELEE_SWING_HIT', 'TREDECIM_MELEE_SWING_HIT', function(playerArg, targetArg, attackArg)
local mainWeapon = playerArg:getEquippedItem(xi.slot.MAIN)
if mainWeapon and mainWeapon:getID() == xi.item.TREDECIM_SCYTHE then
local exData = mainWeapon:getExData()
local count = exData[0]

if count % 13 == 12 then
attackArg:setCritical(true)
end

exData[0] = (count + 1) % 13

mainWeapon:setExData(exData)
end
end)
end

itemObject.onItemUnequip = function(target, item)
target:removeListener('TREDECIM_MELEE_SWING_HIT')
end

return itemObject
2 changes: 2 additions & 0 deletions src/map/entities/battleentity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2169,6 +2169,8 @@ bool CBattleEntity::OnAttack(CAttackState& state, action_t& action)
// Set this attack's critical flag.
attack.SetCritical(xirand::GetRandomNumber(100) < battleutils::GetCritHitRate(this, PTarget, !attack.IsFirstSwing()));

this->PAI->EventHandler.triggerListener("MELEE_SWING_HIT", CLuaBaseEntity(this), CLuaBaseEntity(PTarget), CLuaAttack(&attack));

actionTarget.reaction = REACTION::HIT;

// Critical hit.
Expand Down
2 changes: 2 additions & 0 deletions src/map/lua/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ set(LUA_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/lua_ability.h
${CMAKE_CURRENT_SOURCE_DIR}/lua_action.cpp
${CMAKE_CURRENT_SOURCE_DIR}/lua_action.h
${CMAKE_CURRENT_SOURCE_DIR}/lua_attack.cpp
${CMAKE_CURRENT_SOURCE_DIR}/lua_attack.h
${CMAKE_CURRENT_SOURCE_DIR}/lua_baseentity.cpp
${CMAKE_CURRENT_SOURCE_DIR}/lua_baseentity.h
${CMAKE_CURRENT_SOURCE_DIR}/lua_battlefield.cpp
Expand Down
61 changes: 61 additions & 0 deletions src/map/lua/lua_attack.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
===========================================================================
Copyright (c) 2023 LandSandBoat Dev Teams
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see http://www.gnu.org/licenses/
===========================================================================
*/

#include "lua_attack.h"

#include "attack.h"

CLuaAttack::CLuaAttack(CAttack* attack)
: m_PLuaAttack(attack)
{
if (m_PLuaAttack == nullptr)
{
ShowError("CLuaAttack created with nullptr instead of valid CAttack*!");
}
}

bool CLuaAttack::getCritical() const
{
return m_PLuaAttack->IsCritical();
}

void CLuaAttack::setCritical(bool critical)
{
m_PLuaAttack->SetCritical(critical);
}

//==========================================================//

void CLuaAttack::Register()
{
SOL_USERTYPE("CAttack", CLuaAttack);
SOL_REGISTER("getCritical", CLuaAttack::getCritical);
SOL_REGISTER("setCritical", CLuaAttack::setCritical);
};

std::ostream& operator<<(std::ostream& os, const CLuaAttack& attack)
{
// TODO: Whats a sane log value for this?
std::string id = attack.m_PLuaAttack ? "" : "nullptr";
return os << "CLuaAttack(" << id << ")";
}

//==========================================================//
52 changes: 52 additions & 0 deletions src/map/lua/lua_attack.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
===========================================================================
Copyright (c) 2023 LandSandBoat Dev Teams
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see http://www.gnu.org/licenses/
===========================================================================
*/

#pragma once

#include "common/cbasetypes.h"
#include "luautils.h"

class CAttack;

class CLuaAttack
{
CAttack* m_PLuaAttack;

public:
CLuaAttack(CAttack*);

CAttack* GetAttack() const
{
return m_PLuaAttack;
}

bool getCritical() const;
void setCritical(bool critical);

friend std::ostream& operator<<(std::ostream& out, const CLuaAttack& action);

bool operator==(const CLuaAttack& other) const
{
return this->m_PLuaAttack == other.m_PLuaAttack;
}

static void Register();
};
1 change: 1 addition & 0 deletions src/map/lua/luautils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ namespace luautils
// Register Sol Bindings
CLuaAbility::Register();
CLuaAction::Register();
CLuaAttack::Register();
CLuaBaseEntity::Register();
CLuaBattlefield::Register();
CLuaInstance::Register();
Expand Down
1 change: 1 addition & 0 deletions src/map/lua/luautils.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ extern sol::state lua;

#include "lua_ability.h"
#include "lua_action.h"
#include "lua_attack.h"
#include "lua_baseentity.h"
#include "lua_battlefield.h"
#include "lua_instance.h"
Expand Down

0 comments on commit 23de8d3

Please sign in to comment.