]>
jfr.im git - irc/gameservirc.git/blob - gameserv-2.0/libgameservgldl/src/GameLayer/FightGL.cpp
cd938d3bfb8a65e8a4ef91b081d77a69f4aafac1
1 #include <GameServ/GameLayer/FightGL.h>
2 using GameServ::GameLayer::FightGL
;
4 #include <GameServ/DataLayer/DataAccess.h>
5 using GameServ::DataLayer::DataAccess
;
6 #include <GameServ/DataLayer/IDAOFactory.h>
7 using GameServ::DataLayer::IDAOFactory
;
9 #include <GameServ/Types.h>
10 using GameServ::Types::Range
;
11 using GameServ::Types::Modifiers
;
22 void FightGL::Initialize()
24 // TODO: Load from config
25 shared_ptr
<IDAOFactory
> factory
= DataAccess::GetDataAccessFactory("File");
26 mspPlayerDAO
= factory
->GetPlayerDAO();
29 unsigned int FightGL::PlayerAttackMonster(shared_ptr
<PlayerGO
> spPlayer
, shared_ptr
<MonsterGO
> spMonster
)
31 unsigned int attack
= CalculateAttack(spPlayer
->Strength(), spMonster
->Defense());
32 if (attack
>= spMonster
->Health())
35 spMonster
->Alive(false);
39 spMonster
->Health(spMonster
->Health() - attack
);
44 unsigned int FightGL::MonsterAttackPlayer(shared_ptr
<MonsterGO
> spMonster
, shared_ptr
<PlayerGO
> spPlayer
)
46 unsigned int attack
= CalculateAttack(spMonster
->Strength(), spPlayer
->Defense());
47 if (attack
>= spPlayer
->Health())
50 spPlayer
->Alive(false);
54 spPlayer
->Health(spPlayer
->Health() - attack
);
56 mspPlayerDAO
->Update(spPlayer
);
60 unsigned int FightGL::PlayerAttackPlayer(shared_ptr
<PlayerGO
> spPlayerAttacker
, shared_ptr
<PlayerGO
> spPlayerDefender
)
62 unsigned int attack
= CalculateAttack(spPlayerAttacker
->Strength(), spPlayerDefender
->Defense());
63 if (attack
>= spPlayerDefender
->Health())
65 spPlayerDefender
->Health(0);
66 spPlayerDefender
->Alive(false);
70 spPlayerDefender
->Health(spPlayerDefender
->Health() - attack
);
72 mspPlayerDAO
->Update(spPlayerDefender
);
76 unsigned int FightGL::CalculateAttack(unsigned int strength
, unsigned int defense
)
78 if (defense
>= strength
)
82 Range
<unsigned int> r(strength
, strength
/ 2);
83 if (r
.Random() <= defense
)
89 return r
.LastRandom() - defense
;