20#include "absl/strings/match.h"
21#include "absl/strings/str_cat.h"
26#include "tracy/Tracy.hpp"
33constexpr float kAnyDistance = std::numeric_limits<float>::infinity();
37bool OneMonster(
const skills::Effect& effect) {
38 return effect.damage() > 0 && !effect.all();
42 return std::hypot(monster.x - player.x, monster.z - player.z);
46 return std::hypot(b.x - a.x, b.z - a.z);
50 return std::hypot(place.x - player.x, place.z - player.z);
55template <
typename Unit>
56std::optional<Place> Within(
const std::map<uint32_t, Unit>& units, uint32_t
id,
57 const Player& player,
float reach) {
58 const auto found = units.find(
id);
59 if (found == units.end() || found->second.motion ==
Motion::kDead ||
60 Distance(player, found->second) > reach) {
63 return Place{.x = found->second.x, .z = found->second.z};
68absl::Status Offered() {
69 return Refusal(absl::StatusCode::kFailedPrecondition,
70 Msg(
"You can't, while it's offered in your trade."));
75 return Refusal(absl::StatusCode::kFailedPrecondition,
76 Msg(
"You can't, while you're dead."));
82template <
typename Unit>
83bool InArc(
const Player& player,
const Unit& unit,
float arc) {
87 const float toward = std::atan2(unit.x - player.x, unit.z - player.z);
89 std::remainder(toward - player.yaw, 2.0f * std::numbers::pi_v<float>);
90 return std::abs(off) <= arc / 2.0f * std::numbers::pi_v<float> / 180.0f;
94bool FallenTo(
const Monster& monster,
const monsters::Phase& phase) {
95 return monster.health * 100 <=
96 monster.max_health *
static_cast<int>(phase.health());
99void RunDown(std::map<uint32_t, std::chrono::nanoseconds>& cooldowns,
100 std::chrono::nanoseconds time) {
101 for (
auto it = cooldowns.begin(); it != cooldowns.end();) {
103 it = it->second <= std::chrono::nanoseconds::zero() ? cooldowns.erase(it)
108void Add(
Stats& stats,
const items::Modifier& modifier) {
109 switch (modifier.stat()) {
110 case items::STAT_DAMAGE:
111 stats.damage += modifier.amount();
113 case items::STAT_HEALTH:
114 stats.health += modifier.amount();
116 case items::STAT_ARMOUR:
117 stats.armour += modifier.amount();
127Part List(std::vector<Part> things) {
128 Part list = std::move(things.back());
130 if (!things.empty()) {
132 list =
Of(
Msg(
"$0 and $1", std::move(things.back()), std::move(list)));
135 while (!things.empty()) {
137 list =
Of(
Msg(
"$0, $1", std::move(things.back()), std::move(list)));
144Part Gold(uint32_t gold) {
return Of(
MsgN(
"$0 gold",
"$0 gold", gold, gold)); }
157bool Gain(Player& player, uint32_t experience) {
159 player.experience += experience;
170Sentence InWords(std::chrono::nanoseconds time) {
171 const auto seconds =
static_cast<uint64_t
>(
172 std::chrono::duration_cast<std::chrono::seconds>(time).count());
174 if (seconds % 60 != 0) {
175 return MsgN(
"$0 second",
"$0 seconds", seconds, seconds);
178 return MsgN(
"a minute",
"$0 minutes", seconds / 60, seconds / 60);
185 arg.set_npc(npc.
kind);
186 return {.arg = std::move(arg), .english = npc.
name};
190 const items::Stack* held = player.
inventory.
At(
Worn(items::SLOT_MAIN_HAND));
191 return held !=
nullptr ? held->item() : 0;
195 std::vector<uint32_t> worn;
196 for (
const items::Slot slot :
197 {items::SLOT_OFF_HAND, items::SLOT_HEAD, items::SLOT_BODY,
198 items::SLOT_LEGS, items::SLOT_FEET}) {
200 worn.push_back(item->item());
207 std::shared_ptr<const Content> content,
208 std::shared_ptr<Paths> paths)
209 : terrain_(std::move(
terrain)),
210 content_(std::move(content)),
211 paths_(paths != nullptr ? std::move(paths)
212 : std::make_shared<
Paths>(terrain_)),
223 if (!terrain_.Walkable(player.
x, player.
z)) {
230 const ItemTable& items = content_->items;
232 for (
const items::Stack& stack : items.
starting) {
246 player.
skills.insert(content_->skills.starting.begin(),
247 content_->skills.starting.end());
248 players_[id] = std::move(player);
253 const Part gone =
Name(players_.at(
id).name);
254 if (
const uint32_t other = trades_.End(
id); other != 0) {
255 Tell(other,
Msg(
"$0 has gone, so the trade's off.", gone));
257 if (
const uint32_t other = duels_.End(
id); other != 0) {
258 Tell(other,
Msg(
"$0 has gone, so the duel's off.", gone));
265 const protocol::Place& to, uint32_t count) {
266 const auto found = players_.find(
id);
267 if (found == players_.end()) {
268 return Refusal(absl::StatusCode::kNotFound,
269 Msg(
"There's nobody to move it."));
271 if (trades_.Holds(
id, from) || trades_.Holds(
id, to)) {
274 Player& player = found->second;
275 const absl::Status moved =
277 if (moved.ok() && (from.has_worn() || to.has_worn())) {
284 const auto found = players_.find(
id);
285 if (found == players_.end()) {
286 return Refusal(absl::StatusCode::kNotFound,
287 Msg(
"There's nobody to throw it away."));
289 if (trades_.Holds(
id, place)) {
292 Player& player = found->second;
294 if (destroyed.ok() && place.has_worn()) {
301 const auto found = players_.find(
id);
302 if (found == players_.end()) {
303 return Refusal(absl::StatusCode::kNotFound,
304 Msg(
"There's nobody to use it."));
306 Player& player = found->second;
307 const protocol::Place place =
InBag(slot);
308 if (trades_.Holds(
id, place)) {
311 const items::Stack* stack = player.
inventory.
At(place);
312 if (stack ==
nullptr) {
313 return Refusal(absl::StatusCode::kNotFound,
Msg(
"There's nothing there."));
315 const auto item = content_->items.by_id.find(stack->item());
316 if (item == content_->items.by_id.end()) {
317 return Refusal(absl::StatusCode::kFailedPrecondition,
318 Msg(
"You can't use that."));
320 if (!item->second.has_use()) {
321 return Refusal(absl::StatusCode::kFailedPrecondition,
322 Msg(
"You can't use the $0.",
Of(item->second)));
324 const items::Use& use = item->second.use();
332 absl::StatusCode::kFailedPrecondition,
333 Msg(
"You can use another $0 in $1 s.",
Of(item->second),
334 std::chrono::ceil<std::chrono::seconds>(cooling->second).count()));
337 return Refusal(absl::StatusCode::kFailedPrecondition,
338 Msg(
"You're at full health already."));
340 Heal(
id, player,
static_cast<int>(use.heal()));
341 if (use.cooldown_ms() > 0) {
343 std::chrono::milliseconds(use.cooldown_ms());
346 used.
item = item->first;
352 const auto player = players_.find(
id);
353 const auto found = content_->recipes.find(recipe);
354 if (player == players_.end() || found == content_->recipes.end()) {
355 return Refusal(absl::StatusCode::kNotFound,
Msg(
"There's no such recipe."));
357 const recipes::Recipe& making = found->second;
361 if (player->second.crafting != 0) {
362 return Refusal(absl::StatusCode::kAlreadyExists,
363 Msg(
"You're making something already."));
366 static_cast<int>(making.level())) {
367 return Refusal(absl::StatusCode::kFailedPrecondition,
368 Msg(
"You can make $0 from level $1.",
369 Of(content_->items, making.output().item(),
370 making.output().count()),
374 if (
const absl::StatusOr<Inventory> bag = Made(
id, player->second, making);
378 player->second.crafting = recipe;
379 player->second.crafted = std::chrono::nanoseconds::zero();
380 return absl::OkStatus();
384 const auto found = players_.find(
id);
385 if (found != players_.end()) {
386 Interrupt(
id, found->second);
391 const auto player = players_.find(
id);
392 const auto other = std::ranges::find_if(players_, [name](
const auto& entry) {
393 return absl::EqualsIgnoreCase(entry.second.name, name);
395 if (player == players_.end() || other == players_.end()) {
396 return Refusal(absl::StatusCode::kNotFound,
397 Msg(
"Nobody of that name is here."));
399 if (other == player) {
400 return Refusal(absl::StatusCode::kInvalidArgument,
401 Msg(
"You can't trade with yourself."));
403 const Part asker =
Name(player->second.name);
404 const Part asked =
Name(other->second.name);
405 if (Distance(player->second, other->second) >
kTradeReach) {
406 return Refusal(absl::StatusCode::kOutOfRange,
407 Msg(
"You're too far away to trade with $0.", asked));
409 if (trades_.With(
id) != 0) {
410 return Refusal(absl::StatusCode::kFailedPrecondition,
411 Msg(
"You're trading already."));
413 if (trades_.With(other->first) != 0) {
414 return Refusal(absl::StatusCode::kFailedPrecondition,
415 Msg(
"$0 is trading with someone already.", asked));
417 if (!trades_.Ask(
id, other->first)) {
420 Msg(
"$0 asks to trade. Type /trade $0 to say yes.", asker));
421 Tell(
id,
Msg(
"You asked $0 to trade.", asked));
425 Interrupt(
id, player->second);
426 Interrupt(other->first, other->second);
428 return absl::OkStatus();
432 const protocol::TradeOffer& offer) {
433 const auto player = players_.find(
id);
434 if (player == players_.end()) {
435 return Refusal(absl::StatusCode::kNotFound,
436 Msg(
"There's nobody to trade."));
438 return trades_.Offer(
id, player->second.inventory, content_->items, offer);
443 const uint32_t other = trades_.With(
id);
445 return Refusal(absl::StatusCode::kFailedPrecondition,
446 Msg(
"You're not trading with anyone."));
448 Player& player = players_.at(
id);
449 Player& them = players_.at(other);
450 if (ready && Distance(player, them) >
kTradeReach) {
452 absl::StatusCode::kOutOfRange,
453 Msg(
"You're too far away to trade with $0.",
Name(them.
name)));
455 const absl::StatusOr<bool> both = trades_.Ready(
id, ready, revision);
457 return both.status();
463 const absl::Status traded =
469 Tell(
id,
Msg(
"You traded with $0.",
Name(them.
name)));
470 Tell(other,
Msg(
"You traded with $0.",
Name(player.
name)));
475 if (
const uint32_t other = trades_.End(
id); other != 0) {
476 Tell(other,
Msg(
"$0 called the trade off.",
Name(players_.at(
id).name)));
481 protocol::Trade trade;
482 if (
const uint32_t other = trades_.With(
id); other != 0) {
483 trade.set_partner(players_.at(other).name);
484 *trade.mutable_yours() = trades_.SideOf(
id);
485 *trade.mutable_theirs() = trades_.SideOf(other);
486 trade.set_revision(trades_.RevisionOf(
id));
494 const auto player = players_.find(
id);
495 const auto other = std::ranges::find_if(players_, [name](
const auto& entry) {
496 return absl::EqualsIgnoreCase(entry.second.name, name);
498 if (player == players_.end() || other == players_.end()) {
499 return Refusal(absl::StatusCode::kNotFound,
500 Msg(
"Nobody of that name is here."));
502 if (other == player) {
503 return Refusal(absl::StatusCode::kInvalidArgument,
504 Msg(
"You can't duel yourself."));
509 duel->challenged ==
id && duel->challenger == other->first) {
512 const Part asker =
Name(player->second.name);
513 const Part asked =
Name(other->second.name);
514 if (Distance(player->second, other->second) >
Duels::kReach) {
515 return Refusal(absl::StatusCode::kOutOfRange,
516 Msg(
"You're too far away to duel $0.", asked));
518 if (duels_.Of(
id) !=
nullptr) {
519 return Refusal(absl::StatusCode::kFailedPrecondition,
520 Msg(
"You're in a duel already."));
522 if (duels_.Of(other->first) !=
nullptr) {
523 return Refusal(absl::StatusCode::kFailedPrecondition,
524 Msg(
"$0 is in a duel already.", asked));
526 duels_.Ask(
id, other->first);
529 Msg(
"$0 asks you to duel. Type /duel yes to say yes.", asker));
530 Tell(
id,
Msg(
"You asked $0 to duel.", asked));
531 return absl::OkStatus();
536 if (duel ==
nullptr || duel->
challenged !=
id ||
538 return Refusal(absl::StatusCode::kNotFound,
539 Msg(
"Nobody's asked you to duel."));
542 const Player& challenger = players_.at(asker);
543 const Player& player = players_.at(
id);
546 Tell(asker,
Msg(
"$0 said no to a duel.",
Name(player.
name)));
547 return absl::OkStatus();
552 absl::StatusCode::kOutOfRange,
553 Msg(
"You're too far away to duel $0.",
Name(challenger.
name)));
555 duels_.Accept(
id, {.x = challenger.
x, .z = challenger.
z});
557 Interrupt(
id, players_.at(
id));
558 Interrupt(asker, players_.at(asker));
559 return absl::OkStatus();
564 if (duel ==
nullptr) {
565 return Refusal(absl::StatusCode::kNotFound,
Msg(
"You're not in a duel."));
569 return absl::OkStatus();
571 const uint32_t other = duels_.End(
id);
572 Tell(other,
Msg(
"$0 called the duel off.",
Name(players_.at(
id).name)));
573 return absl::OkStatus();
579 protocol::Duel shown;
581 if (duel ==
nullptr) {
584 const uint32_t other = duel->
Against(
id);
585 shown.set_opponent(players_.at(other).name);
586 shown.set_opponent_id(other);
587 switch (duel->
state) {
589 shown.set_state(duel->
challenger ==
id ? protocol::DUEL_ASKING
590 : protocol::DUEL_ASKED);
593 shown.set_state(protocol::DUEL_COUNTDOWN);
594 shown.set_countdown(
static_cast<uint32_t
>(
595 std::chrono::duration_cast<std::chrono::milliseconds>(duel->
left)
599 shown.set_state(protocol::DUEL_FIGHTING);
602 shown.mutable_flag()->set_x(duel->
flag.
x);
603 shown.mutable_flag()->set_z(duel->
flag.
z);
610 const auto found = players_.find(
id);
611 if (found != players_.end()) {
612 found->second.guild = guild;
618 for (
const War& war : wars) {
619 wars_[war.challenger] = war;
620 wars_[war.challenged] = war;
625 const auto player = players_.find(
id);
626 const auto them = players_.find(other);
627 if (player == players_.end() || them == players_.end() || other ==
id) {
630 return other == duels_.Opponent(
id) ||
631 WarBetween(player->second, them->second) !=
nullptr;
634const War* World::WarBetween(
const Player& player,
const Player& other)
const {
636 const auto war = wars_.find(player.
guild);
637 if (war == wars_.end() || war->second.Against(player.
guild) != other.
guild) {
644 return std::exchange(war_kills_, {});
647void World::Dress(
Player& player)
const {
653 const skills::Effect& effect = player.
effect;
654 const uint32_t first =
655 effect.blows_size() > 0 ? effect.blows(0).at_ms() : effect.hit_ms();
656 landed = player.
cast >= std::chrono::milliseconds(first);
659 for (
const auto& [slot, stack] : player.
inventory.
items().worn()) {
660 const auto item = content_->items.by_id.find(stack.item());
661 if (item == content_->items.by_id.end()) {
664 for (
const items::Modifier& modifier : item->second.equip().modifiers()) {
665 Add(player.
stats, modifier);
667 for (
const items::Modifier& roll : stack.rolls()) {
668 Add(player.
stats, roll);
670 if (slot == items::SLOT_MAIN_HAND && item->second.has_weapon()) {
680 !landed && content_->skills.by_id.at(player.
skill).effect().weapon()) {
691 const uint32_t
id = next_monster_++;
692 monsters_[id] = monster;
697 const uint32_t
id = next_npc_++;
698 npcs_[id] = std::move(npc);
703 const auto found = players_.find(
id);
704 if (found == players_.end() || !std::isfinite(x) || !std::isfinite(z)) {
709 const float length = std::hypot(x, z);
714 found->second.input_x = x;
715 found->second.input_z = z;
716 found->second.input_run = run;
717 found->second.input_attack = attack;
721 const auto found = players_.find(
id);
722 if (found == players_.end()) {
727 const bool hostile = player != 0 &&
Hostile(
id, player);
728 found->second.target = hostile ? 0 : monster;
729 found->second.target_player = hostile ? player : 0;
733 const auto found = players_.find(
id);
734 if (found != players_.end()) {
735 found->second.behind = behind;
740 const auto found = players_.find(
id);
741 if (found == players_.end()) {
744 Player& player = found->second;
746 player.
respawn > std::chrono::nanoseconds::zero()) {
757 const auto found = players_.find(
id);
758 if (found == players_.end() || found->second.motion ==
Motion::kDead ||
759 !std::isfinite(to.
x) || !std::isfinite(to.
z)) {
762 Player& player = found->second;
763 const std::vector<Place> way = paths_->Find({player.
x, player.
z}, to);
764 player.
way.assign(way.begin(), way.end());
768 const auto found = players_.find(
id);
769 if (found != players_.end()) {
770 found->second.input_skill = skill;
775 const auto player = players_.find(
id);
776 const auto trainer = npcs_.find(npc);
777 const auto taught = content_->
skills.by_id.find(skill);
778 if (player == players_.end() || trainer == npcs_.end() ||
779 !trainer->second.teaches.contains(skill) ||
780 taught == content_->
skills.by_id.end()) {
781 return Refusal(absl::StatusCode::kNotFound,
782 Msg(
"Nobody here teaches that."));
784 if (std::hypot(trainer->second.x - player->second.
x,
785 trainer->second.z - player->second.
z) >
kTalkReach) {
787 absl::StatusCode::kOutOfRange,
788 Msg(
"You're too far away to learn from the $0.",
Of(trainer->second)));
790 const uint32_t level = taught->second.level();
793 absl::StatusCode::kFailedPrecondition,
794 Msg(
"You can learn $0 from level $1.",
Of(taught->second), level));
796 if (player->second.
skills.contains(skill)) {
797 return Refusal(absl::StatusCode::kAlreadyExists,
798 Msg(
"You know $0 already.",
Of(taught->second)));
800 player->second.
skills.insert(skill);
801 return absl::OkStatus();
805 const auto player = players_.find(
id);
806 const auto giver = npcs_.find(npc);
807 const auto given = content_->
quests.find(quest);
808 if (player == players_.end() || giver == npcs_.end() ||
809 given == content_->
quests.end() ||
810 given->second.giver() != giver->second.kind) {
811 return Refusal(absl::StatusCode::kNotFound,
812 Msg(
"Nobody here gives that quest."));
814 if (std::hypot(giver->second.x - player->second.
x,
815 giver->second.z - player->second.
z) >
kTalkReach) {
818 absl::StatusCode::kOutOfRange,
819 Msg(
"You're too far away to talk to the $0.",
Of(giver->second)));
821 if (player->second.
quests.contains(quest)) {
822 return Refusal(absl::StatusCode::kAlreadyExists,
823 Msg(
"You're on $0 already.",
Of(given->second)));
826 return Refusal(absl::StatusCode::kAlreadyExists,
827 Msg(
"You've done $0 already.",
Of(given->second)));
829 player->second.
quests[quest] = 0;
832 return absl::OkStatus();
836 const auto player = players_.find(
id);
837 const auto herald = npcs_.find(npc);
838 const factions::Faction* faction =
839 herald != npcs_.end() ?
HeraldOf(content_->factions, herald->second.kind)
841 if (player == players_.end() || faction ==
nullptr) {
842 return Refusal(absl::StatusCode::kNotFound,
843 Msg(
"Nobody here swears players to a faction."));
845 if (std::hypot(herald->second.x - player->second.
x,
846 herald->second.z - player->second.
z) >
kTalkReach) {
848 absl::StatusCode::kOutOfRange,
849 Msg(
"You're too far away to talk to the $0.",
Of(herald->second)));
852 if (
const auto sworn = content_->factions.find(player->second.
faction);
853 sworn != content_->factions.end()) {
855 return Refusal(absl::StatusCode::kAlreadyExists,
856 Msg(
"You're sworn to $0 already.",
Of(sworn->second)));
858 player->second.
faction = faction->id();
860 Tell(
id,
Msg(
"You've joined $0.",
Of(*faction)));
861 return absl::OkStatus();
865 const auto player = players_.find(
id);
866 if (player == players_.end() || !player->second.
quests.contains(quest)) {
867 return Refusal(absl::StatusCode::kNotFound,
868 Msg(
"You're not on that quest."));
870 player->second.
quests.erase(quest);
872 return absl::OkStatus();
876 const auto player = players_.find(
id);
877 const auto giver = npcs_.find(npc);
878 const auto given = content_->
quests.find(quest);
879 if (player == players_.end() || giver == npcs_.end() ||
880 given == content_->
quests.end() ||
881 given->second.giver() != giver->second.kind) {
882 return Refusal(absl::StatusCode::kNotFound,
883 Msg(
"Nobody here takes that quest."));
885 if (std::hypot(giver->second.x - player->second.
x,
886 giver->second.z - player->second.
z) >
kTalkReach) {
888 absl::StatusCode::kOutOfRange,
889 Msg(
"You're too far away to talk to the $0.",
Of(giver->second)));
891 const quests::Quest& done = given->second;
892 const auto on = player->second.
quests.find(quest);
893 if (on == player->second.
quests.end()) {
894 return Refusal(absl::StatusCode::kNotFound,
895 Msg(
"You're not on $0.",
Of(done)));
897 if (on->second < done.kill().count()) {
900 return Refusal(absl::StatusCode::kFailedPrecondition,
901 Msg(
"$0 asks for $1, and you've killed $2.",
Of(done),
902 done.kill().count(), on->second));
906 std::vector<Part> prizes = {
Of(
MsgN(
"$0 experience",
"$0 experience",
907 done.experience(), done.experience()))};
908 for (
const quests::Prize& prize : done.prizes()) {
909 const auto item = content_->items.by_id.find(prize.item());
910 if (item == content_->items.by_id.end()) {
913 if (Give(bag, prize.item(), prize.count()) < prize.count()) {
914 return Refusal(absl::StatusCode::kResourceExhausted,
915 Msg(
"Your bag is full. Make room for the prizes first."));
917 prizes.push_back(
Of(item->second, prize.count()));
919 player->second.
inventory = std::move(bag);
921 for (
const quests::Prize& prize : done.prizes()) {
924 given.
item = prize.item();
925 given.
count = prize.count();
931 player->second.
quests.erase(on);
936 Tell(
id,
Msg(
"You've done $0, for $1.",
Of(done), List(std::move(prizes))));
937 return absl::OkStatus();
945 for (
auto& [
id, player] : players_) {
946 Act(
id, player, time);
950 for (
const auto& [boss, phase] : std::exchange(calls_, {})) {
951 CallAdds(boss, phase);
953 for (
auto& [
id, monster] : monsters_) {
958 std::erase_if(monsters_, [
this](
const auto& entry) {
959 const uint32_t boss = entry.second.called_by;
963 const auto found = monsters_.find(boss);
964 return found == monsters_.end() ||
965 (found->second.motion !=
Motion::kDead && found->second.phase == 0);
968 for (
const auto& [
id, player] : players_) {
969 history_.Record(
id, clock_, {.x = player.
x, .z = player.
z});
973void World::Act(uint32_t
id,
Player& player, std::chrono::nanoseconds time) {
984 std::max(player.
respawn - time, std::chrono::nanoseconds::zero());
988 const skills::Effect& effect = player.
effect;
989 const auto before = player.
cast;
991 Stride(player, effect);
994 once.set_at_ms(effect.hit_ms());
995 once.set_push(effect.push());
996 const int blows = std::max(effect.blows_size(), 1);
997 for (
int index = 0; index < blows; ++index) {
998 const skills::Blow& blow =
999 effect.blows_size() > 0 ? effect.blows(index) : once;
1000 const std::chrono::milliseconds hit(blow.at_ms());
1003 if (before < hit && player.cast >= hit && armed) {
1004 Land(
id, player, effect, blow, index, blows);
1007 if (player.
cast < std::chrono::milliseconds(effect.cast_ms())) {
1012 const skills::Skill& done = content_->skills.by_id.at(player.
skill);
1013 player.
chain = done.next();
1014 player.
chain_left = std::chrono::milliseconds(done.window_ms());
1017 std::max(player.
chain_left - time, std::chrono::nanoseconds::zero());
1022 player.
chain != 0 &&
1023 player.
chain_left > std::chrono::nanoseconds::zero()
1025 : content_->skills.attack;
1030 const bool walking = player.
input_x != 0.0f || player.
input_z != 0.0f;
1034 Interrupt(
id, player);
1036 Make(
id, player, time);
1043 const skills::Skill* skill = Usable(player, player.
input_skill);
1044 const skills::Effect effect =
1045 skill !=
nullptr ? EffectOf(player, *skill) : skills::Effect();
1046 const bool far = OneMonster(effect) &&
1047 Target(player, kAnyDistance).has_value() &&
1048 !Target(player, effect.reach()).has_value();
1049 if (skill !=
nullptr && !far) {
1051 Start(player, *skill);
1054 if (skill !=
nullptr && !walking) {
1055 Approach(player, effect.reach(), time);
1060 if (!player.
way.empty()) {
1061 Follow(player, time);
1067void World::Move(
Player& player, std::chrono::nanoseconds time) {
1068 Go(player, player.input_x, player.input_z, player.input_run, time);
1071void World::Go(
Player& player,
float to_x,
float to_z,
bool run,
1072 std::chrono::nanoseconds time) {
1075 WalkAlong(terrain_, x, z, to_x, to_z, run,
1076 std::chrono::duration<float>(time).count());
1079 const float dx = x - player.x;
1080 const float dz = z - player.z;
1081 if (dx == 0.0f && dz == 0.0f) {
1085 player.yaw = std::atan2(dx, dz);
1091void World::Follow(
Player& player, std::chrono::nanoseconds time) {
1092 player.steered =
true;
1093 const Place next = player.way.front();
1094 const float distance = std::hypot(next.x - player.x, next.z - player.z);
1095 const float step =
kRunSpeed * std::chrono::duration<float>(time).count();
1096 if (distance > 0.0f) {
1098 const float share = std::min(distance / step, 1.0f);
1099 const float x = player.x;
1100 const float z = player.z;
1101 Go(player, (next.x - x) / distance * share, (next.z - z) / distance * share,
1104 if (player.x == x && player.z == z) {
1109 if (distance <= step) {
1110 player.way.pop_front();
1114void World::Approach(
Player& player,
float reach,
1115 std::chrono::nanoseconds time) {
1116 player.steered =
true;
1117 const std::optional<Place> to = Target(player, kAnyDistance);
1121 const float distance = std::hypot(to->x - player.x, to->z - player.z);
1122 const float step =
kRunSpeed * std::chrono::duration<float>(time).count();
1125 std::clamp((distance - reach *
kCloseIn) / step, 0.0f, 1.0f);
1126 Go(player, (to->x - player.x) / distance * share,
1127 (to->z - player.z) / distance * share,
true, time);
1130std::optional<Place> World::Target(
const Player& player,
float reach)
const {
1131 if (player.target_player == 0) {
1132 return Within(monsters_, player.target, player, reach);
1136 if (!Within(players_, player.target_player, player, kAnyDistance)) {
1137 return std::nullopt;
1139 const Place seen = Seen(player, player.target_player);
1140 if (Distance(player, seen) > reach) {
1141 return std::nullopt;
1146Place World::Seen(
const Player& player, uint32_t other)
const {
1147 if (player.behind > std::chrono::nanoseconds::zero()) {
1148 if (
const std::optional<Place> then =
1149 history_.At(other, clock_ - player.behind)) {
1153 const Player& them = players_.at(other);
1154 return {.x = them.x, .z = them.z};
1159void World::Aim(
Player& player,
float reach) {
1160 if (
const std::optional<Place> at = Target(player, reach)) {
1161 player.yaw = std::atan2(at->x - player.x, at->z - player.z);
1165const skills::Skill* World::Usable(
const Player& player, uint32_t
id)
const {
1166 const auto found = content_->skills.by_id.find(
id);
1167 if (found == content_->skills.by_id.end() || !player.skills.contains(
id) ||
1168 player.cooldowns.contains(
id)) {
1171 const skills::Effect& effect = found->second.effect();
1173 ? player.stats.weapon ==
nullptr
1174 : OneMonster(effect) && !Target(player, kAnyDistance).has_value()) {
1177 return &found->second;
1180skills::Effect World::EffectOf(
const Player& player,
1181 const skills::Skill& skill)
const {
1182 skills::Effect effect = skill.effect();
1183 const items::Weapon* weapon = player.stats.weapon;
1184 if (effect.weapon() && weapon !=
nullptr) {
1185 const float pace = effect.pace() > 0.0f ? effect.pace() : 1.0f;
1186 auto paced = [pace](uint32_t whole) {
1187 return static_cast<uint32_t
>(
1188 std::lround(pace *
static_cast<float>(whole)));
1190 effect.set_reach(weapon->reach());
1191 effect.set_damage(std::max(paced(weapon->damage()), 1u));
1192 effect.set_cast_ms(paced(weapon->swing_ms()));
1193 effect.set_hit_ms(paced(weapon->hit_ms()));
1198void World::Start(
Player& player,
const skills::Skill& skill) {
1200 player.skill = skill.id();
1201 player.cast = std::chrono::nanoseconds::zero();
1205 player.effect = EffectOf(player, skill);
1206 player.cast_weapon = player.stats.weapon;
1207 if (skill.cooldown_ms() > 0) {
1208 player.cooldowns[skill.id()] =
1209 std::chrono::milliseconds(skill.cooldown_ms());
1211 Aim(player, player.effect.reach());
1212 player.cast_x = player.x;
1213 player.cast_z = player.z;
1218void World::Stride(
Player& player,
const skills::Effect& effect) {
1219 if (effect.strides_size() == 0) {
1223 effect, std::chrono::duration<float, std::milli>(player.cast).count());
1224 const float edge = terrain_.edge();
1225 Walk(terrain_, player.x, player.z,
1226 std::clamp(player.cast_x + std::sin(player.yaw) * ahead, -edge, edge),
1227 std::clamp(player.cast_z + std::cos(player.yaw) * ahead, -edge, edge));
1230void World::Land(uint32_t
id,
Player& player,
const skills::Effect& effect,
1231 const skills::Blow& blow,
int index,
int blows) {
1234 Heal(
id, player,
static_cast<int>(effect.heal()));
1236 if (effect.damage() == 0) {
1243 effect.weapon() && effect.pace() > 0.0f ? effect.pace() : 1.0f;
1245 static_cast<int>(effect.damage()) +
1246 static_cast<int>(std::lround(
1247 pace *
static_cast<float>(
ExtraDamage(level) + player.stats.damage)));
1248 const int damage = total / blows + (index == blows - 1 ? total % blows : 0);
1251 for (
auto& [monster_id, monster] : monsters_) {
1252 if ((effect.all() || monster_id == player.target) &&
1254 Distance(player, monster) <= effect.reach() &&
1255 InArc(player, monster, effect.arc())) {
1258 if (!monster.boss()) {
1259 Push(player, monster, blow.push());
1260 Throw(monster, blow.lift());
1262 Hurt(
id, player, monster_id, monster, damage);
1274 if (duels_.Opponent(
id) == 0 && !wars_.contains(player.guild)) {
1277 for (
auto& [other, them] : players_) {
1278 if ((!effect.all() && other != player.target_player) ||
1282 const Place seen = Seen(player, other);
1283 if (Distance(player, seen) <= effect.reach() &&
1284 InArc(player, seen, effect.arc())) {
1285 Hurt(
id, other, them, damage);
1292void World::Push(
const Player& player,
Monster& monster,
float metres) {
1293 const float distance = Distance(player, monster);
1294 if (metres == 0.0f || distance == 0.0f) {
1297 monster.pushed_from_x = monster.x;
1298 monster.pushed_from_z = monster.z;
1299 monster.push_x = (monster.x - player.x) / distance * metres;
1300 monster.push_z = (monster.z - player.z) / distance * metres;
1301 monster.pushed = std::chrono::nanoseconds::zero();
1307bool World::Slide(
Monster& monster, std::chrono::nanoseconds time) {
1312 std::min<std::chrono::nanoseconds>(monster.pushed + time,
kPushTime);
1313 const float done = std::chrono::duration<float>(monster.pushed) /
1314 std::chrono::duration<float>(
kPushTime);
1315 const float eased = 1.0f - (1.0f - done) * (1.0f - done);
1316 const float edge = terrain_.edge();
1317 Walk(terrain_, monster.x, monster.z,
1318 std::clamp(monster.pushed_from_x + monster.push_x * eased, -edge, edge),
1319 std::clamp(monster.pushed_from_z + monster.push_z * eased, -edge, edge));
1325void World::Throw(
Monster& monster,
float lift) {
1326 const bool flying = monster.height > 0.0f || monster.rise > 0.0f;
1329 const bool spent = flying ? monster.in_air >=
kMostInAir
1330 : monster.steady > std::chrono::nanoseconds::zero();
1331 if (spent && lift >= 0.0f) {
1336 if (lift > monster.height) {
1337 monster.rise = std::max(
1338 monster.rise, std::sqrt(2.0f *
kGravity * (lift - monster.height)));
1339 }
else if (lift < 0.0f && flying) {
1340 monster.rise = -std::sqrt(2.0f *
kGravity * -lift);
1341 }
else if (flying) {
1342 monster.rise = std::max(monster.rise,
kPop);
1352bool World::Fly(
Monster& monster, std::chrono::nanoseconds time) {
1353 if (monster.height <= 0.0f && monster.rise <= 0.0f) {
1355 std::max(monster.steady - time, std::chrono::nanoseconds::zero());
1358 monster.in_air += time;
1361 monster.rise = std::min(monster.rise, 0.0f);
1363 const float seconds = std::chrono::duration<float>(time).count();
1364 monster.height += (monster.rise -
kGravity * seconds / 2.0f) * seconds;
1365 monster.rise -=
kGravity * seconds;
1366 if (monster.height <= 0.0f) {
1367 monster.height = 0.0f;
1368 monster.rise = 0.0f;
1369 monster.in_air = std::chrono::nanoseconds::zero();
1376void World::Hurt(uint32_t
id,
Player& player, uint32_t monster_id,
1377 Monster& monster,
int damage) {
1379 const int taken = std::min(damage, monster.health);
1380 monster.threat[id] += taken;
1381 monster.health -= taken;
1383 hit.monster = monster.kind;
1384 hit.monster_id = monster_id;
1385 hit.amount =
static_cast<uint32_t
>(damage);
1386 if (monster.health > 0) {
1388 while (monster.phase + 1 < monster.phases.size() &&
1389 FallenTo(monster, monster.phases[monster.phase + 1])) {
1391 calls_.emplace_back(monster_id, monster.phase);
1396 monster.respawn = monster.respawn_time;
1398 for (
auto& [add_id, add] : monsters_) {
1399 if (add.called_by == monster_id) {
1404 if (!monster.boss()) {
1405 Reward(
id, player, monster);
1411 const Player* most =
nullptr;
1414 for (
const auto& [helper, threat] : monster.threat) {
1415 const auto found = players_.find(helper);
1416 if (found == players_.end() ||
1417 threat * 100 < monster.max_health *
kEnoughHelp) {
1420 Reward(helper, found->second, monster);
1422 if (threat > taken_most) {
1423 most = &found->second;
1424 taken_most = threat;
1427 const Sentence again = InWords(monster.respawn_time);
1428 Announce(monster, [&](Part boss) {
1429 if (most ==
nullptr) {
1430 return Msg(
"The $0 has fallen. It rises again in $1.", std::move(boss),
1436 return Msg(
"The $0 has fallen to $1. It rises again in $2.",
1437 std::move(boss),
Name(most->name), again);
1441 return MsgN(
"The $0 has fallen to $1 and $2 other. It rises again in $3.",
1442 "The $0 has fallen to $1 and $2 others. It rises again in $3.",
1443 static_cast<uint64_t
>(helped - 1), std::move(boss),
1444 Name(most->name), helped - 1, again);
1448void World::Reward(uint32_t
id,
Player& player,
const Monster& monster) {
1450 if (
Gain(player, monster.experience)) {
1454 Loot(
id, player, monster);
1455 Count(
id, player, monster);
1458void World::Hurt(uint32_t from, uint32_t
id,
Player& player,
int damage) {
1460 Interrupt(
id, player);
1463 if (from != duels_.Opponent(
id)) {
1464 const int taken = std::min(damage, player.health);
1465 player.health -= taken;
1467 static_cast<uint32_t
>(taken);
1468 if (player.health > 0) {
1475 const Player& killer = players_.at(from);
1476 war_kills_.push_back({.war = WarBetween(killer, player)->id,
1479 .guild = killer.guild});
1484 const int taken = std::min(damage, player.health - 1);
1486 player.health -= taken;
1488 static_cast<uint32_t
>(taken);
1490 if (taken < damage) {
1495void World::Heal(uint32_t
id,
Player& player,
int health) {
1496 const int healed = std::min(health,
MaxHealthOf(player) - player.health);
1500 player.health += healed;
1504void World::Loot(uint32_t
id,
Player& player,
const Monster& monster) {
1505 const auto kind = content_->monsters.kinds.find(monster.kind);
1506 if (kind == content_->monsters.kinds.end()) {
1509 std::vector<Part> kept;
1510 std::vector<Part> left;
1511 for (
const monsters::Drop& drop : kind->second.loot()) {
1512 const auto item = content_->items.by_id.find(drop.item());
1513 if (item == content_->items.by_id.end() ||
1514 !std::bernoulli_distribution(drop.chance())(random_)) {
1517 const uint32_t least = std::max(drop.min(), 1u);
1518 const uint32_t count = std::uniform_int_distribution(
1519 least, std::max(drop.max(), least))(random_);
1520 const uint32_t fitted = Give(player.inventory, drop.item(), count);
1522 kept.push_back(
Of(item->second, fitted));
1524 looted.monster = monster.kind;
1525 looted.item = drop.item();
1526 looted.count = fitted;
1528 if (fitted < count) {
1529 left.push_back(
Of(item->second, count - fitted));
1533 if (
const monsters::Gold& gold = kind->second.gold(); gold.max() > 0) {
1534 const uint32_t coins =
1535 std::uniform_int_distribution(gold.min(), gold.max())(random_);
1536 if (
const uint32_t carried = coins - player.inventory.AddGold(coins);
1538 kept.push_back(Gold(carried));
1541 if (!kept.empty()) {
1545 Msg(
"The $0 dropped $1.",
Of(kind->second), List(std::move(kept))));
1547 if (!left.empty()) {
1549 Tell(
id,
Msg(
"Your bag is full, so you left $0 behind.",
1550 List(std::move(left))));
1554void World::Count(uint32_t
id,
Player& player,
const Monster& monster) {
1555 const auto kind = content_->monsters.kinds.find(monster.kind);
1556 for (
auto& [quest, kills] : player.quests) {
1557 const auto found = content_->quests.find(quest);
1558 if (found == content_->quests.end() ||
1559 kind == content_->monsters.kinds.end()) {
1562 const quests::Kill& kill = found->second.kill();
1563 if (kill.monster() != monster.kind || kills >= kill.count()) {
1567 ++player.quests_revision;
1568 const Part asked =
Of(kind->second, kill.count());
1569 const auto giver = content_->npcs.kinds.find(found->second.giver());
1570 if (kills == kill.count() && giver != content_->npcs.kinds.end()) {
1574 Tell(
id,
Msg(
"$0: $1 of $2 killed. Go back to the $3.",
Of(found->second),
1575 kills, asked,
Of(giver->second)));
1580 Tell(
id,
Msg(
"$0: $1 of $2 killed.",
Of(found->second), kills, asked));
1584uint32_t World::Give(
Inventory& bag, uint32_t item, uint32_t count) {
1585 const auto found = content_->items.by_id.find(item);
1586 if (found == content_->items.by_id.end()) {
1591 const bool stacks =
StackSize(found->second) > 1;
1592 const uint32_t each = stacks ? count : 1;
1593 uint32_t fitted = 0;
1594 for (uint32_t made = 0; made < count; made += each) {
1596 stack.set_item(item);
1597 stack.set_count(each);
1601 for (
const items::Roll& roll : found->second.rolls()) {
1602 items::Modifier* rolled = stack.add_rolls();
1603 rolled->set_stat(roll.stat());
1605 std::uniform_int_distribution(roll.min(), roll.max())(random_));
1607 fitted += each - bag.Add(content_->items, stack);
1612absl::StatusOr<Inventory> World::Made(uint32_t
id,
const Player& player,
1613 const recipes::Recipe& recipe) {
1614 const recipes::ItemCount& output = recipe.output();
1617 Inventory bag = player.inventory;
1618 for (
const recipes::ItemCount& input : recipe.inputs()) {
1620 uint32_t left = input.count();
1621 for (uint32_t slot = 0; slot < kBagSlots && left > 0; ++slot) {
1622 const items::Stack* stack = bag.At(
InBag(slot));
1623 if (stack ==
nullptr || stack->item() != input.item() ||
1624 trades_.Holds(
id,
InBag(slot))) {
1627 const uint32_t taken = std::min(left,
CountOf(*stack));
1629 if (absl::Status took = bag.Take(
InBag(slot), taken); !took.ok()) {
1637 return Refusal(absl::StatusCode::kFailedPrecondition,
1638 Msg(
"You need $0 in your bag to make $1.",
1639 Of(content_->items, input.item(), input.count()),
1640 Of(content_->items, output.item(), output.count())));
1644 if (Give(bag, output.item(), output.count()) < output.count()) {
1645 return Refusal(absl::StatusCode::kResourceExhausted,
1646 Msg(
"Your bag is full. Make room for $0 first.",
1647 Of(content_->items, output.item(), output.count())));
1652void World::Make(uint32_t
id,
Player& player, std::chrono::nanoseconds time) {
1654 const auto found = content_->recipes.find(player.crafting);
1655 if (found == content_->recipes.end()) {
1658 player.crafted += time;
1659 const recipes::Recipe& recipe = found->second;
1660 if (player.crafted < std::chrono::seconds(recipe.seconds())) {
1663 player.crafting = 0;
1665 Of(content_->items, recipe.output().item(), recipe.output().count());
1667 absl::StatusOr<Inventory> bag = Made(
id, player, recipe);
1670 Tell(
id,
Msg(
"You couldn't make $0. $1", made,
SentenceOf(bag.status())));
1673 player.inventory = *std::move(bag);
1675 crafted.item = recipe.output().item();
1676 crafted.count = recipe.output().count();
1677 Tell(
id,
Msg(
"You made $0.", made));
1680void World::Interrupt(uint32_t
id,
Player& player) {
1681 const auto found = content_->recipes.find(player.crafting);
1682 if (found == content_->recipes.end()) {
1685 const recipes::ItemCount& output = found->second.output();
1686 Tell(
id,
Msg(
"You stopped making $0.",
1687 Of(content_->items, output.item(), output.count())));
1688 player.crafting = 0;
1693void World::Tell(uint32_t player,
Sentence said, protocol::Channel channel) {
1694 notices_.push_back({.player = player,
1695 .text = std::move(said.
english),
1696 .message = std::move(said.
message),
1697 .channel = channel});
1703 return events_.emplace_back(
Event{.kind = kind,
1704 .player = player.
name,
1706 .land = player.
land,
1711void World::Referee(std::chrono::nanoseconds time) {
1712 for (
const Duels::Duel& asked : duels_.Step(time)) {
1713 Tell(asked.challenger,
Msg(
"$0 didn't answer, so there's no duel.",
1714 Name(players_.at(asked.challenged).name)));
1717 std::vector<uint32_t> losers;
1718 for (
const auto& [challenger, duel] : duels_.all()) {
1722 for (
const uint32_t side : {duel.challenger, duel.challenged}) {
1723 const Player& player = players_.at(side);
1724 const bool strayed =
1725 std::hypot(player.x - duel.flag.x, player.z - duel.flag.z) >
1728 Tell(side,
Msg(
"You went too far from the flag."));
1731 losers.push_back(side);
1736 for (
const uint32_t loser : losers) {
1741void World::Lose(uint32_t
id) {
1742 const uint32_t winner = duels_.End(
id);
1744 players_.at(
id).target_player = 0;
1745 players_.at(winner).target_player = 0;
1746 Tell(
id,
Msg(
"$0 won the duel.",
Name(players_.at(winner).name)));
1747 Tell(winner,
Msg(
"You won the duel against $0.",
Name(players_.at(
id).name)));
1750void World::Act(
Monster& monster, std::chrono::nanoseconds time) {
1752 RunDown(monster.cooldowns, time);
1759 if (monster.called_by != 0) {
1762 const std::chrono::nanoseconds before = monster.respawn;
1763 Revive(monster, time, random_);
1766 Announce(monster, [](Part boss) {
1767 return Msg(
"The $0 has risen.", std::move(boss));
1769 }
else if (monster.boss() && before >
kRisesSoon &&
1771 Announce(monster, [](Part boss) {
1772 return Msg(
"The $0 rises again in $1.", std::move(boss),
1779 const bool pushed = Slide(monster, time);
1780 if (Fly(monster, time)) {
1784 const auto before = monster.swing;
1785 monster.swing += time;
1786 if (before < monster.hit_time && monster.swing >= monster.hit_time) {
1789 if (monster.swing < monster.swing_time) {
1796 monster.cast += time;
1798 std::chrono::milliseconds(monster.casting.telegraph_ms())) {
1808 Hunt(monster, players_, terrain_, time, random_);
1811void World::CallAdds(uint32_t
id, std::size_t phase) {
1812 const Monster& boss = monsters_.at(
id);
1816 for (
const monsters::Add& add : boss.phases[phase].adds()) {
1817 const auto kind = content_->monsters.kinds.find(add.kind());
1818 if (kind == content_->monsters.kinds.end()) {
1822 for (uint32_t i = 0; i < add.count(); ++i) {
1823 const float angle = 2.0f * std::numbers::pi_v<float> *
1824 static_cast<float>(i) /
1825 static_cast<float>(add.count());
1828 if (!terrain_.Walkable(x, z)) {
1833 Monster called =
MonsterOf(kind->second, x, z);
1834 called.called_by = id;
1835 called.sight = boss.sight;
1836 called.leash = boss.leash;
1837 Spawn(std::move(called));
1842void World::Announce(
const Monster& boss,
1844 const auto kind = content_->monsters.kinds.find(boss.kind);
1845 if (kind == content_->monsters.kinds.end()) {
1848 const Sentence line = news(
Of(kind->second));
1849 for (
const auto& [
id, player] : players_) {
1850 Tell(
id, line, protocol::CHANNEL_LAND);
1854void World::Hit(
Monster& monster) {
1855 const auto found = players_.find(monster.prey);
1856 if (found == players_.end()) {
1859 Player& player = found->second;
1861 Distance(player, monster) > monster.reach) {
1864 Hit(found->first, player, monster, monster.damage);
1867void World::Hit(uint32_t
id,
Player& player,
const Monster& monster,
int blow) {
1869 Interrupt(
id, player);
1871 const int damage = std::max(blow - player.stats.armour, 1);
1872 player.health = std::max(player.health - damage, 0);
1874 hurt.monster = monster.kind;
1875 hurt.amount =
static_cast<uint32_t
>(damage);
1876 if (player.health > 0) {
1885void World::LandSkill(
const Monster& monster) {
1886 const Place aimed{.x = monster.cast_x, .z = monster.cast_z};
1887 for (
auto& [
id, player] : players_) {
1889 InShape(monster.casting, aimed, monster.yaw,
1890 {.x = player.x, .z = player.z})) {
1891 Hit(
id, player, monster,
static_cast<int>(monster.casting.damage()));
static constexpr float kFlagReach
static constexpr float kReach
A player asks another within this many metres of them.
bool Wear(const ItemTable &table, const items::Stack &stack)
absl::Status Destroy(const protocol::Place &place)
Throws away all of what's at the place.
uint32_t revision() const
absl::Status Move(const ItemTable &table, const protocol::Place &from, const protocol::Place &to, uint32_t count=0)
absl::Status TakeOne(const protocol::Place &place)
Takes one off the stack at the place, as using one does.
uint32_t Add(const ItemTable &table, const items::Stack &stack)
const protocol::Inventory & items() const
const items::Stack * At(const protocol::Place &place) const
What's at the place, or nullptr when it's empty, or isn't a place.
void Number(const ItemTable &table)
void Step(std::chrono::nanoseconds time)
const Terrain & terrain() const
protocol::Duel DuelOf(uint32_t id) const
World(uint32_t seed=std::mt19937::default_seed, Terrain terrain=Terrain(), std::shared_ptr< const Content > content=std::make_shared< Content >(), std::shared_ptr< Paths > paths=nullptr)
std::vector< Notice > TakeNotices()
The lines for players since the last time, which it hands over.
void SetGuild(uint32_t id, uint32_t guild)
The player's guild, by its id, or 0 for none.
void Join(uint32_t id, Player player)
std::vector< Event > TakeEvents()
What's happened since the last time, which it hands over.
protocol::Trade TradeOf(uint32_t id) const
absl::Status Craft(uint32_t id, uint32_t recipe)
absl::StatusOr< uint32_t > ReadyToTrade(uint32_t id, bool ready, uint32_t revision)
absl::Status AnswerDuel(uint32_t id, bool yes)
static constexpr float kAddsAround
How far from a boss its adds come, in metres.
std::set< uint32_t > TakeTradeNews()
void UseSkill(uint32_t id, uint32_t skill)
void Pick(uint32_t id, uint32_t monster, uint32_t player=0)
static constexpr std::chrono::seconds kRespawnTime
void StopCrafting(uint32_t id)
Stops what the player's making, if anything, and they lose nothing.
std::vector< WarKill > TakeWarKills()
absl::Status Learn(uint32_t id, uint32_t npc, uint32_t skill)
static constexpr int kEnoughHelp
absl::Status TakeQuest(uint32_t id, uint32_t npc, uint32_t quest)
static constexpr std::chrono::seconds kRisesSoon
How long before a boss comes back to life its land hears that it will.
void WalkTo(uint32_t id, Place to)
absl::Status AskToTrade(uint32_t id, std::string_view name)
void Respawn(uint32_t id)
uint32_t Spawn(Monster monster)
absl::Status OfferToTrade(uint32_t id, const protocol::TradeOffer &offer)
What the player offers in their trade, as Trades::Offer has it.
absl::Status MoveItem(uint32_t id, const protocol::Place &from, const protocol::Place &to, uint32_t count=0)
static constexpr float kCloseIn
void SetInput(uint32_t id, float x, float z, bool run, bool attack=false)
absl::Status TurnIn(uint32_t id, uint32_t npc, uint32_t quest)
static constexpr float kTalkReach
absl::Status Enlist(uint32_t id, uint32_t npc)
uint32_t CallOffDuel(uint32_t id)
absl::Status DestroyItem(uint32_t id, const protocol::Place &place)
Throws away all of what's at the place, unless they offer it in a trade.
void SetBehind(uint32_t id, std::chrono::nanoseconds behind)
absl::Status AskToDuel(uint32_t id, std::string_view name)
void SetWars(const std::vector< War > &wars)
absl::Status Yield(uint32_t id)
static constexpr float kTradeReach
Two players trade within talking reach, as close as they'd stand to talk.
std::set< uint32_t > TakeDuelNews()
void CancelTrade(uint32_t id)
Calls the player's trade off, for both of them.
absl::Status UseItem(uint32_t id, uint32_t slot)
bool Hostile(uint32_t id, uint32_t other) const
static constexpr float kRunSpeed
absl::Status GiveUp(uint32_t id, uint32_t quest)
Vector3 Place(const Point &point, const Terrain &terrain)
const factions::Faction * HeraldOf(const std::map< uint32_t, factions::Faction > &factions, uint32_t kind)
uint32_t CountOf(const items::Stack &stack)
How many are in the stack, which is one when it doesn't say.
bool InShape(const monsters::Skill &skill, Place from, float yaw, Place place)
Sentence MsgN(std::string_view one, std::string_view many, uint64_t count, Parts... parts)
std::chrono::nanoseconds RandomRest(std::mt19937 &random)
absl::Status Refusal(absl::StatusCode code, const Sentence &why)
Sentence SentenceOf(const absl::Status &status)
constexpr std::chrono::milliseconds kPushTime
How long a blow's push takes, fast at first and slowing, as a shove does.
Level LevelFor(uint32_t experience)
float AheadAt(const skills::Effect &effect, float ms)
void Hunt(Monster &monster, const std::map< uint32_t, Player > &players, const Terrain &terrain, std::chrono::nanoseconds time, std::mt19937 &random)
uint32_t StackSize(const items::Item &item)
How many of the item go in one slot of a bag.
protocol::Place Worn(items::Slot slot)
A slot that's worn.
Sentence Msg(std::string_view text, Parts... parts)
void Walk(const Terrain &terrain, float &x, float &z, float to_x, float to_z)
protocol::Place InBag(uint32_t slot)
A place in the bag, by its slot from zero.
std::vector< uint32_t > WornOf(const Player &player)
Part Name(std::string_view name)
int MaxHealthOf(const Player &player)
Monster MonsterOf(const monsters::Kind &kind, float x, float z)
Part Of(const items::Item &item, uint32_t count)
int ExtraDamage(int level)
What a level adds to the damage of the weapon a player holds.
uint32_t MainHandOf(const Player &player)
void Revive(Monster &monster, std::chrono::nanoseconds time, std::mt19937 &random)
bool Dead(const protocol::World &seen, uint32_t monster)
constexpr std::chrono::milliseconds kMostInAir
void WalkAlong(const Terrain &terrain, float &x, float &z, float direction_x, float direction_z, bool run, float seconds)
constexpr std::chrono::milliseconds kSteady
std::chrono::nanoseconds left
How long the ask has left, and then the countdown.
uint32_t challenger
Who asked, and who they asked, by their ids.
uint32_t Against(uint32_t id) const
The other side from the player's, by their id.
uint32_t item
An item dropped, given for a quest, used or made, and how many.
The items in the items file, by id.
std::vector< items::Stack > starting
What each new player starts with.
std::chrono::nanoseconds rest
uint32_t kind
By its id in the NPCs file.
In metres from the middle of a land.
std::chrono::nanoseconds respawn
While they're dead, how long until they can come back.
const items::Weapon * cast_weapon
std::set< uint32_t > skills
The skills the player knows, by their ids in the skills file.
int land
Which of the world's lands, by its place in kLands.
uint32_t input_skill
A skill the player asked for, which waits until they're free.
std::set< uint32_t > quests_done
The quests they've turned in, which they can't take again.
std::chrono::nanoseconds cast
std::chrono::nanoseconds chain_left
std::map< uint32_t, std::chrono::nanoseconds > item_cooldowns
std::map< uint32_t, uint32_t > quests
std::map< uint32_t, std::chrono::nanoseconds > cooldowns
How long until each skill they've used is ready again, by its id.
Inventory inventory
What the player carries and wears.
protocol::Message message
const items::Weapon * weapon
The weapon in the player's main hand, from the content, or nullptr.