]>
Commit | Line | Data |
---|---|---|
1 | #include <GameServ/GameLayer/FightGL.h>\r | |
2 | using GameServ::GameLayer::FightGL;\r | |
3 | \r | |
4 | #include <GameServ/DataLayer/DataAccess.h>\r | |
5 | using GameServ::DataLayer::DataAccess;\r | |
6 | #include <GameServ/DataLayer/IDAOFactory.h>\r | |
7 | using GameServ::DataLayer::IDAOFactory;\r | |
8 | \r | |
9 | #include <GameServ/Types.h>\r | |
10 | using GameServ::Types::Range;\r | |
11 | using GameServ::Types::Modifiers;\r | |
12 | \r | |
13 | FightGL::FightGL()\r | |
14 | {\r | |
15 | Initialize();\r | |
16 | }\r | |
17 | \r | |
18 | FightGL::~FightGL()\r | |
19 | {\r | |
20 | }\r | |
21 | \r | |
22 | void FightGL::Initialize()\r | |
23 | {\r | |
24 | // TODO: Load from config\r | |
25 | shared_ptr<IDAOFactory> factory = DataAccess::GetDataAccessFactory("File");\r | |
26 | mspPlayerDAO = factory->GetPlayerDAO();\r | |
27 | }\r | |
28 | \r | |
29 | unsigned int FightGL::PlayerAttackMonster(shared_ptr<PlayerGO> spPlayer, shared_ptr<MonsterGO> spMonster)\r | |
30 | {\r | |
31 | unsigned int attack = CalculateAttack(spPlayer->Strength(), spMonster->Defense());\r | |
32 | if (attack >= spMonster->Health())\r | |
33 | {\r | |
34 | spMonster->Health(0);\r | |
35 | spMonster->Alive(false);\r | |
36 | }\r | |
37 | else\r | |
38 | {\r | |
39 | spMonster->Health(spMonster->Health() - attack);\r | |
40 | }\r | |
41 | return attack;\r | |
42 | }\r | |
43 | \r | |
44 | unsigned int FightGL::MonsterAttackPlayer(shared_ptr<MonsterGO> spMonster, shared_ptr<PlayerGO> spPlayer)\r | |
45 | {\r | |
46 | unsigned int attack = CalculateAttack(spMonster->Strength(), spPlayer->Defense());\r | |
47 | if (attack >= spPlayer->Health())\r | |
48 | {\r | |
49 | spPlayer->Health(0);\r | |
50 | spPlayer->Alive(false);\r | |
51 | }\r | |
52 | else\r | |
53 | {\r | |
54 | spPlayer->Health(spPlayer->Health() - attack);\r | |
55 | }\r | |
56 | return attack;\r | |
57 | }\r | |
58 | \r | |
59 | unsigned int FightGL::PlayerAttackPlayer(shared_ptr<PlayerGO> spPlayerAttacker, shared_ptr<PlayerGO> spPlayerDefender)\r | |
60 | {\r | |
61 | unsigned int attack = CalculateAttack(spPlayerAttacker->Strength(), spPlayerDefender->Defense());\r | |
62 | if (attack >= spPlayerDefender->Health())\r | |
63 | {\r | |
64 | spPlayerDefender->Health(0);\r | |
65 | spPlayerDefender->Alive(false);\r | |
66 | }\r | |
67 | else\r | |
68 | {\r | |
69 | spPlayerDefender->Health(spPlayerDefender->Health() - attack);\r | |
70 | }\r | |
71 | return attack;\r | |
72 | }\r | |
73 | \r | |
74 | unsigned int FightGL::CalculateAttack(unsigned int strength, unsigned int defense)\r | |
75 | {\r | |
76 | if (defense >= strength)\r | |
77 | {\r | |
78 | return 0;\r | |
79 | }\r | |
80 | Range<unsigned int> r(strength, strength / 2);\r | |
81 | if (r.Random() <= defense)\r | |
82 | {\r | |
83 | return 0;\r | |
84 | }\r | |
85 | else\r | |
86 | {\r | |
87 | return r.LastRandom() - defense;\r | |
88 | }\r | |
89 | } |