FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
GLKeeper/src/EconomyService.cpp at main · codenamecpp/GLKeeper · GitHub
codenamecpp
/
GLKeeper
Public
Notifications
You must be signed in to change notification settings
Fork
4
Star
40
Code
Issues
0
Pull requests
0
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Security and quality
Insights
Expand file tree
Breadcrumbs
GLKeeper
/
src
/
EconomyService.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
146 lines (118 loc) · 3.98 KB
Breadcrumbs
GLKeeper
/
src
/
EconomyService.cpp
Copy path
File metadata and controls
146 lines (118 loc) · 3.98 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#
include
"
stdafx.h
"
#
include
"
EconomyService.h
"
#
include
"
GameSession.h
"
#
include
"
GameEventBus.h
"
#
include
"
RoomManager.h
"
//
////////////////////////////////////////////////////////////////////////
EconomyService
gEconomyService
;
//
////////////////////////////////////////////////////////////////////////
void
EconomyService::EnterWorld
()
{
IssueStartingResources
();
}
void
EconomyService::ClearWorld
()
{
}
void
EconomyService::UpdateFrame
(
float
deltaTime)
{
}
void
EconomyService::UpdateLogic
(
float
stepDeltaTime)
{
}
long
EconomyService::GiveResource
(ePlayerID playerId, eGameResource resourceType,
long
resourceAmount)
{
return
GiveResource
(
gGameSession
.
GetPlayer
(playerId), resourceType, resourceAmount);
}
long
EconomyService::GiveResource
(Player& player, eGameResource resourceType,
long
resourceAmount)
{
if
(resourceAmount <
1
)
return
0
;
if
(player.
IsNonPlayer
())
{
cxx_assert
(
false
);
return
0
;
}
if
(resourceType == eGameResource_Gold)
{
long
moneyAmountLeft = resourceAmount;
for
(
const
EntityHandle roomHandle: player.
GetOwnedMoneyStorageRooms
())
{
Room* roomInstance =
gRoomManager
.
GetRoomPtr
(roomHandle);
cxx_assert
(roomInstance);
if
(roomInstance ==
nullptr
)
continue
;
if
(
auto
* moneyStorage = roomInstance->
GetCapability
<MoneyStorageRoomCapability>())
{
long
storedMoney = moneyStorage->
StoreGold
(moneyAmountLeft);
moneyAmountLeft -= storedMoney;
if
(moneyAmountLeft <=
0
)
break
;
}
}
cxx_assert
(moneyAmountLeft >=
0
);
return
(resourceAmount - moneyAmountLeft);
}
if
(resourceType == eGameResource_Mana)
{
cxx_assert
(
false
);
}
return
0
;
}
long
EconomyService::TakeResource
(ePlayerID playerId, eGameResource resourceType,
long
resourceAmount)
{
return
TakeResource
(
gGameSession
.
GetPlayer
(playerId), resourceType, resourceAmount);
}
long
EconomyService::TakeResource
(Player& player, eGameResource resourceType,
long
resourceAmount)
{
if
(resourceAmount <
1
)
return
0
;
if
(player.
IsNonPlayer
())
{
cxx_assert
(
false
);
return
0
;
}
if
(resourceType == eGameResource_Gold)
{
long
moneyAmountLeft = resourceAmount;
for
(
const
EntityHandle roomHandle: player.
GetOwnedMoneyStorageRooms
())
{
Room* roomInstance =
gRoomManager
.
GetRoomPtr
(roomHandle);
cxx_assert
(roomInstance);
if
(roomInstance ==
nullptr
)
continue
;
if
(
auto
* moneyStorage = roomInstance->
GetCapability
<MoneyStorageRoomCapability>())
{
long
removedMoney = moneyStorage->
DisposeGold
(moneyAmountLeft);
moneyAmountLeft -= removedMoney;
if
(moneyAmountLeft <=
0
)
break
;
}
}
cxx_assert
(moneyAmountLeft >=
0
);
return
(resourceAmount - moneyAmountLeft);
}
if
(resourceType == eGameResource_Mana)
{
cxx_assert
(
false
);
}
return
0
;
}
void
EconomyService::StoredMoneyAmountChanged
(ePlayerID playerId, EntityHandle roomHandle,
long
amountDelta)
{
cxx_assert
(amountDelta !=
0
);
if
(amountDelta !=
0
)
{
//
update cache
Player& player =
gGameSession
.
GetPlayer
(playerId);
player.
ChangeResourceAmount
(eGameResource_Gold, amountDelta);
//
issue global event
gGameEventBus
.
Send_ResourceAmountChanged
(playerId, eGameResource_Gold);
}
}
void
EconomyService::IssueStartingResources
()
{
for
(Player& player:
gGameSession
.
GetPlayers
())
{
if
(player.
IsNonPlayer
())
continue
;
//
money
long
startingMoney = player.
GetStartingResourceAmount
(eGameResource_Gold);
if
(startingMoney >
0
)
{
GiveResource
(player, eGameResource_Gold, startingMoney);
}
}
}
Back
|
FazBrowse Home
|
New Git URL