This commit is contained in:
aozhiwei 2023-05-18 17:10:24 +08:00
parent 58a28ac44c
commit ac0bd31e99
4 changed files with 89 additions and 0 deletions

View File

@ -0,0 +1,62 @@
#include "precompile.h"
#include "compose.h"
#include "creature.h"
#include "netdata.h"
#include "trigger.h"
#include "room.h"
#include "effect.h"
#include "weapon.h"
#include "human.h"
#include "mt/GraspBuff.h"
#include "mt/Grasp.h"
#include "mt/Hero.h"
#include "mt/Equip.h"
Compose::Compose(Creature* owner)
{
owner_ = owner;
}
Compose::~Compose()
{
}
void Compose::Init()
{
if (owner_->IsPlayer()) {
TakeOnWeapon(owner_->GetCurrWeapon());
owner_->GetTrigger()->AddListener
(
kTakeonWeaponEvent,
[this] (const a8::Args& args) mutable
{
Weapon* old_weapon = args.Get<Weapon*>(0);
Weapon* new_weapon = args.Get<Weapon*>(1);
TakeOnWeapon(new_weapon);
}
);
}
}
void Compose::Clear()
{
for (int buff_uniid : hold_buffs_) {
owner_->RemoveBuffByUniId(buff_uniid);
}
hold_buffs_.clear();
}
void Compose::TakeOnWeapon(Weapon* weapon)
{
std::set<int>* buffs = mt::Grasp::GetBuffs(owner_->AsHuman()->meta->id(),
owner_->GetBattleContext()->GetHeroLevel(),
weapon->meta->id());
Clear();
if (buffs) {
for (int buff_id : *buffs) {
hold_buffs_.push_back(owner_->TryAddBuff(owner_, buff_id, nullptr));
}
}
}

View File

@ -0,0 +1,23 @@
#pragma once
#include "trigger.h"
class Creature;
class Weapon;
class Compose
{
public:
Compose(Creature* owner);
~Compose();
void Init();
private:
void Clear();
void TakeOnWeapon(Weapon* weapon);
private:
Creature* owner_ = nullptr;
std::vector<int> hold_buffs_;
};

View File

@ -29,6 +29,7 @@
#include "stats.h"
#include "team.h"
#include "bornpoint.h"
#include "compose.h"
#include "mt/Param.h"
#include "mt/Hero.h"
@ -70,6 +71,7 @@ Creature::Creature():MoveableEntity()
inventory_[IS_1XSCOPE].num = 1;
movement_ = std::make_shared<Movement>(this);
gun_grasp_ = std::make_shared<GunGrasp>(this);
compose_ = std::make_shared<Compose>(this);
}
Creature::~Creature()

View File

@ -64,6 +64,7 @@ class DelayAddBuffHandle;
class Movement;
class Player;
class GunGrasp;
class Compose;
class Android;
class Creature : public MoveableEntity
{
@ -434,6 +435,7 @@ private:
std::array<Inventory, IS_END> inventory_ = {};
std::shared_ptr<GunGrasp> gun_grasp_;
std::shared_ptr<Compose> compose_;
friend class Buff;
friend class AddInventoryBuff;