From 46ebb0296b4a86dad702525762273ba5a8d1e544 Mon Sep 17 00:00:00 2001 From: ch4rindo <103165856+ch4rindo@users.noreply.github.com> Date: Thu, 3 Nov 2022 17:29:25 +0900 Subject: [PATCH 1/3] =?UTF-8?q?=E3=83=97=E3=83=AC=E3=82=A4=E3=83=A4?= =?UTF-8?q?=E3=83=BC=E3=81=AE=E3=82=B9=E3=83=86=E3=83=BC=E3=82=BF=E3=82=B9?= =?UTF-8?q?=E3=82=92=E7=A2=BA=E8=AA=8D=E3=81=99=E3=82=8B=E3=82=B3=E3=83=9E?= =?UTF-8?q?=E3=83=B3=E3=83=89=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Main.php | 2 ++ src/core/PlayerStatsViewer.php | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 src/core/PlayerStatsViewer.php diff --git a/src/Main.php b/src/Main.php index 977d4c7..1102582 100644 --- a/src/Main.php +++ b/src/Main.php @@ -17,6 +17,7 @@ use NeiroNetwork\AlternativeCoreWars\core\PlayerBlockTracker; use NeiroNetwork\AlternativeCoreWars\core\GameArenaProtector; use NeiroNetwork\AlternativeCoreWars\core\PlayerKillAssistsEventMaker; +use NeiroNetwork\AlternativeCoreWars\core\PlayerStatsViewer; use NeiroNetwork\AlternativeCoreWars\core\PrivateCraftingForBrewingAndSmelting; use NeiroNetwork\AlternativeCoreWars\core\RewardGiver; use NeiroNetwork\AlternativeCoreWars\core\ServerSpecificationNormalizer; @@ -70,6 +71,7 @@ protected function onLoad() : void{ ShopCreator::class, DropItemReplacer::class, KitEventBroker::class, + PlayerStatsViewer::class, ]); } diff --git a/src/core/PlayerStatsViewer.php b/src/core/PlayerStatsViewer.php new file mode 100644 index 0000000..69dd9a5 --- /dev/null +++ b/src/core/PlayerStatsViewer.php @@ -0,0 +1,32 @@ +getServer()->getCommandMap()->register($this->getName(), new class("stats") extends Command{ + public function __construct(string $name){ parent::__construct($name, "自分のステータスを確認します"); } + public function execute(CommandSender $sender, string $commandLabel, array $args){ + if($sender instanceof Player){ + $sender->sendMessage( + TextFormat::BOLD . "========== " . $sender->getName() . " さんのステータス ==========" . PHP_EOL . + InfoAPI::resolve(TextFormat::BOLD . "所持金: {money} Money", new PlayerInfo($sender)) . PHP_EOL . + InfoAPI::resolve(TextFormat::BOLD . "経験値: {exp} EXP", new PlayerInfo($sender)) . PHP_EOL . + InfoAPI::resolve(TextFormat::BOLD . "音色ポイント: {np} NP", new PlayerInfo($sender)) + ); + } + } + }); + } +} From 2719733fdd48d85a5d3329d8d2cdb284b15531c8 Mon Sep 17 00:00:00 2001 From: Nerahikada Date: Sun, 6 Nov 2022 19:42:22 +0900 Subject: [PATCH 2/3] =?UTF-8?q?=E3=82=B3=E3=83=9E=E3=83=B3=E3=83=89?= =?UTF-8?q?=E4=B8=80=E6=8B=AC=E7=94=9F=E6=88=90=E3=81=99=E3=82=8B=E3=82=B5?= =?UTF-8?q?=E3=83=96=E3=83=97=E3=83=A9=E3=82=B0=E3=82=A4=E3=83=B3=E3=82=92?= =?UTF-8?q?=E4=BD=9C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/command/PlayerStatsCommand.php | 34 ++++++++++++++++++++++++++++++ src/core/CommandFactory.php | 17 +++++++++++++++ src/core/PlayerStatsViewer.php | 32 ---------------------------- 3 files changed, 51 insertions(+), 32 deletions(-) create mode 100644 src/command/PlayerStatsCommand.php create mode 100644 src/core/CommandFactory.php delete mode 100644 src/core/PlayerStatsViewer.php diff --git a/src/command/PlayerStatsCommand.php b/src/command/PlayerStatsCommand.php new file mode 100644 index 0000000..4e81d18 --- /dev/null +++ b/src/command/PlayerStatsCommand.php @@ -0,0 +1,34 @@ +hasPermission(DefaultPermissions::ROOT_OPERATOR) ? implode(" ", $args) : ""; + $target = $sender->getServer()->getPlayerByPrefix($target) ?? $sender; + if($target instanceof Player){ + $sender->sendMessage(InfoAPI::resolve( + TextFormat::GOLD . "========== " . TextFormat::WHITE . "{$sender->getName()} さんのステータス " . TextFormat::GOLD . "==========" . TextFormat::RESET . PHP_EOL . + "所持金: {money} Money" . PHP_EOL . + "経験値: {exp} EXP" . PHP_EOL . + "音色ポイント: {np} NP", + new PlayerInfo($target) + )); + } + } +} diff --git a/src/core/CommandFactory.php b/src/core/CommandFactory.php new file mode 100644 index 0000000..762ce5d --- /dev/null +++ b/src/core/CommandFactory.php @@ -0,0 +1,17 @@ +getServer()->getCommandMap()->registerAll($this->getName(), [ + new PlayerStatsCommand(), + ]); + } +} diff --git a/src/core/PlayerStatsViewer.php b/src/core/PlayerStatsViewer.php deleted file mode 100644 index 69dd9a5..0000000 --- a/src/core/PlayerStatsViewer.php +++ /dev/null @@ -1,32 +0,0 @@ -getServer()->getCommandMap()->register($this->getName(), new class("stats") extends Command{ - public function __construct(string $name){ parent::__construct($name, "自分のステータスを確認します"); } - public function execute(CommandSender $sender, string $commandLabel, array $args){ - if($sender instanceof Player){ - $sender->sendMessage( - TextFormat::BOLD . "========== " . $sender->getName() . " さんのステータス ==========" . PHP_EOL . - InfoAPI::resolve(TextFormat::BOLD . "所持金: {money} Money", new PlayerInfo($sender)) . PHP_EOL . - InfoAPI::resolve(TextFormat::BOLD . "経験値: {exp} EXP", new PlayerInfo($sender)) . PHP_EOL . - InfoAPI::resolve(TextFormat::BOLD . "音色ポイント: {np} NP", new PlayerInfo($sender)) - ); - } - } - }); - } -} From 1c3086c981d5abb98d1a91364a7e8d37598b73d1 Mon Sep 17 00:00:00 2001 From: Nerahikada Date: Sun, 6 Nov 2022 19:43:00 +0900 Subject: [PATCH 3/3] =?UTF-8?q?WIP:=20=E3=81=95=E3=82=89=E3=81=AA=E3=82=8B?= =?UTF-8?q?=E3=83=97=E3=83=AC=E3=82=A4=E3=83=A4=E3=83=BC=E3=82=B9=E3=83=86?= =?UTF-8?q?=E3=83=BC=E3=82=BF=E3=82=B9=E3=81=AE=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Main.php | 4 +-- src/core/PlayerActivityTracker.php | 46 ++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 src/core/PlayerActivityTracker.php diff --git a/src/Main.php b/src/Main.php index 1102582..36b3354 100644 --- a/src/Main.php +++ b/src/Main.php @@ -17,7 +17,7 @@ use NeiroNetwork\AlternativeCoreWars\core\PlayerBlockTracker; use NeiroNetwork\AlternativeCoreWars\core\GameArenaProtector; use NeiroNetwork\AlternativeCoreWars\core\PlayerKillAssistsEventMaker; -use NeiroNetwork\AlternativeCoreWars\core\PlayerStatsViewer; +use NeiroNetwork\AlternativeCoreWars\core\CommandFactory; use NeiroNetwork\AlternativeCoreWars\core\PrivateCraftingForBrewingAndSmelting; use NeiroNetwork\AlternativeCoreWars\core\RewardGiver; use NeiroNetwork\AlternativeCoreWars\core\ServerSpecificationNormalizer; @@ -71,7 +71,7 @@ protected function onLoad() : void{ ShopCreator::class, DropItemReplacer::class, KitEventBroker::class, - PlayerStatsViewer::class, + CommandFactory::class, ]); } diff --git a/src/core/PlayerActivityTracker.php b/src/core/PlayerActivityTracker.php new file mode 100644 index 0000000..80e520b --- /dev/null +++ b/src/core/PlayerActivityTracker.php @@ -0,0 +1,46 @@ +kills = $api->completeConfig(["currency" => "kills"]); + $this->assists = $api->completeConfig(["currency" => "assists"]); + $this->deaths = $api->completeConfig(["currency" => "deaths"]); + $this->breaks = $api->completeConfig(["currency" => "breaks"]); + $this->victories = $api->completeConfig(["currency" => "victories"]); + $this->defeats = $api->completeConfig(["currency" => "defeats"]); + $this->playtime = $api->completeConfig(["currency" => "playtime"]); + }); + } + + private function increase(Player $player, Complete $schema, LabelSet $label = null) : void{ + Capital::api("0.1.0", function(Capital $api) use ($player, $schema, $label){ + yield from $api->addMoney($this->getName(), $player, $schema, 1, $label ?? new LabelSet([])); + }); + } + + public function onDeath(PlayerDeathWithoutDeathScreenEvent $event) : void{ + $player = $event->getPlayer(); + $last = $player->getLastDamageCause(); + + $this->increase($player, $this->deaths, new LabelSet(["cause" => $last->getCause()])); + if($last instanceof EntityDamageByEntityEvent && ($damager = $last->getEntity()) instanceof Player){ + $this->increase($damager, $this->kills, new LabelSet(["cause" => $last->getCause()])); + } + } +}