MCPcopy Create free account
hub / github.com/THUDM/AgentTuning / take_damage

Method take_damage

AgentBench.old/src/tasks/card_game/logic/src/fish.cpp:192–252  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

190*/
191
192opt Fish::take_damage(Fish* src, int dmg){
193 if(state == FishState::DEAD) return nullopt;
194 debug_msg("Fish take damage");
195 J json;
196 int d = dmg;
197 int live_fishs = ally->count_live_fish();
198 if(check_buff(Fish::SHIELD) && src) {
199 remove_buff(Fish::SHIELD);
200 d *= 0.3;
201 json["passive"].append(passive_to_json("reduce", (original ? original : this)->pos, ally->player_id, 0.3, update_timestamp()));
202 }
203 if(check_buff(Fish::DEFLECT) && src && live_fishs > 1) {
204 remove_buff(Fish::DEFLECT);
205 int cnt = 0;
206 auto e = ally->get_fishs();
207 for(auto i: e)
208 if(i != this && i != original && i->state != FishState::DEAD)
209 ++cnt;
210 // if (cnt > 0) d /= cnt;
211 json["passive"].append(passive_to_json("deflect", (original ? original : this)->pos, ally->player_id, d, update_timestamp()));
212 int dd = d * 0.3;
213 for(auto i:e)
214 if(i->state != Fish::DEAD && i != this && i != original) {
215 add_json(json, (i->take_damage(nullptr, dd / cnt)).value());
216 }
217 d = d * 0.7;
218 }
219 // int tmp = d;
220 // auto e = ally->get_fishs();
221 // for(auto i: e)
222 // if(i->attach_target == this && i->attach_type == 0){
223 // i->take_damage(nullptr, tmp*0.4);
224 // d -= tmp*0.4;
225 // }
226 if(src) {
227 json["hit"].append(hit_to_json((original ? original : this)->pos, ally->player_id, d, true, update_timestamp()));
228 } else {
229 json["hit"].append(hit_to_json((original ? original : this)->pos, ally->player_id, d, false, update_timestamp()));
230 }
231 hp -= d;
232 wound += d;
233 if(hp <= 0){
234 debug_msg("Fish take damage dead");
235 //state = DEAD;
236 //在行动结束后处理DEAD!
237 return json;
238 }
239 /*if(hp <= int(0.1*max_hp) && check_buff(FishBuff::HEAL)) {
240 remove_buff(FishBuff::HEAL);
241 json["passive"].append(passive_to_json("heal", (original ? original : this)->pos, ally->player_id, heal_hp(0.15*max_hp)));
242 }*/
243 if(check_buff(FishBuff::LIFEONHIT) && src) {
244 remove_buff(FishBuff::LIFEONHIT);
245 json["passive"].append(passive_to_json("heal", (original ? original : this)->pos, ally->player_id, heal_hp(20), update_timestamp()));
246 }
247 /*if(check_buff(FishBuff::SWELL) && src) {
248 add_json(json, (src->take_damage(nullptr, dmg)).value());
249 json["passive"].append(passive_to_json("counter", (original ? original : this)->pos, ally->player_id, 0));

Callers 3

specialMethod · 0.80
explodeMethod · 0.80
on_damagedMethod · 0.80

Calls 7

passive_to_jsonFunction · 0.85
add_jsonFunction · 0.85
hit_to_jsonFunction · 0.85
randomFunction · 0.85
count_live_fishMethod · 0.80
valueMethod · 0.80
get_fishsMethod · 0.45

Tested by

no test coverage detected