From 512ade66a477673d636b3691b10d9a30a01d9765 Mon Sep 17 00:00:00 2001 From: destoer Date: Sat, 25 Nov 2023 15:56:27 +0000 Subject: [PATCH] impl basic lr stats --- src/Jail.cs | 1 + src/LastRequest/Dodgeball.cs | 2 +- src/LastRequest/Grenade.cs | 2 +- src/LastRequest/GunToss.cs | 2 +- src/LastRequest/HeadshotOnly.cs | 2 +- src/LastRequest/LRBase.cs | 11 +++++--- src/LastRequest/LRKnife.cs | 2 +- src/LastRequest/LastRequest.cs | 42 +++++++++++++++-------------- src/LastRequest/ScoutKnife.cs | 2 +- src/LastRequest/ShotForShot.cs | 2 +- src/LastRequest/ShotgunWar.cs | 2 +- src/LastRequest/Stats.cs | 48 +++++++++++++++++++++++++++++++-- 12 files changed, 85 insertions(+), 33 deletions(-) diff --git a/src/Jail.cs b/src/Jail.cs index f92ef81..a7f7eab 100644 --- a/src/Jail.cs +++ b/src/Jail.cs @@ -101,6 +101,7 @@ void register_commands() // reg lr commands AddCommand("lr","start an lr",lr.lr_cmd); AddCommand("cancel_lr","admin : cancel lr",lr.cancel_lr_cmd); + AddCommand("lr_stats","list lr stats",lr.lr_stats.lr_stats_cmd); // reg sd commands AddCommand("sd","start and sd",sd.sd_cmd); diff --git a/src/LastRequest/Dodgeball.cs b/src/LastRequest/Dodgeball.cs index 7772b51..911757d 100644 --- a/src/LastRequest/Dodgeball.cs +++ b/src/LastRequest/Dodgeball.cs @@ -15,7 +15,7 @@ public class LRDodgeball : LRBase { - public LRDodgeball(LastRequest manager,int lr_slot, int player_slot, String choice) : base(manager,"Dodgeball",lr_slot,player_slot,choice) + public LRDodgeball(LastRequest manager,LastRequest.LRType type,int lr_slot, int player_slot, String choice) : base(manager,type,lr_slot,player_slot,choice) { } diff --git a/src/LastRequest/Grenade.cs b/src/LastRequest/Grenade.cs index 7282dc8..ebcfaa5 100644 --- a/src/LastRequest/Grenade.cs +++ b/src/LastRequest/Grenade.cs @@ -15,7 +15,7 @@ public class LRGrenade : LRBase { - public LRGrenade(LastRequest manager,int lr_slot, int player_slot, String choice) : base(manager,"Grenade",lr_slot,player_slot,choice) + public LRGrenade(LastRequest manager,LastRequest.LRType type,int lr_slot, int player_slot, String choice) : base(manager,type,lr_slot,player_slot,choice) { } diff --git a/src/LastRequest/GunToss.cs b/src/LastRequest/GunToss.cs index 4666ad1..173690c 100644 --- a/src/LastRequest/GunToss.cs +++ b/src/LastRequest/GunToss.cs @@ -13,7 +13,7 @@ public class LRGunToss : LRBase { - public LRGunToss(LastRequest manager,int lr_slot, int player_slot, String choice) : base(manager,"Gun toss",lr_slot,player_slot,choice) + public LRGunToss(LastRequest manager,LastRequest.LRType type,int lr_slot, int player_slot, String choice) : base(manager,type,lr_slot,player_slot,choice) { } diff --git a/src/LastRequest/HeadshotOnly.cs b/src/LastRequest/HeadshotOnly.cs index 4877022..2add684 100644 --- a/src/LastRequest/HeadshotOnly.cs +++ b/src/LastRequest/HeadshotOnly.cs @@ -13,7 +13,7 @@ public class LRHeadshotOnly : LRBase { - public LRHeadshotOnly(LastRequest manager,int lr_slot, int player_slot, String choice) : base(manager,"Headshot only",lr_slot,player_slot,choice) + public LRHeadshotOnly(LastRequest manager,LastRequest.LRType type,int lr_slot, int player_slot, String choice) : base(manager,type,lr_slot,player_slot,choice) { } diff --git a/src/LastRequest/LRBase.cs b/src/LastRequest/LRBase.cs index 3897c98..b798761 100644 --- a/src/LastRequest/LRBase.cs +++ b/src/LastRequest/LRBase.cs @@ -22,13 +22,14 @@ enum LrState ACTIVE, } - protected LRBase(LastRequest lr_manager,String name,int lr_slot,int actor_slot, String lr_choice) + protected LRBase(LastRequest lr_manager,LastRequest.LRType lr_type,int lr_slot,int actor_slot, String lr_choice) { state = LrState.PENDING; slot = lr_slot; player_slot = actor_slot; choice = lr_choice; - lr_name = name; + lr_name = LastRequest.LR_NAME[(int)type]; + type = lr_type; // while lr is pending damage is off restrict_damage = true; @@ -102,7 +103,9 @@ public void lose() return; } - Lib.announce(LastRequest.LR_PREFIX,$"{player.PlayerName} lost {lr_name}, {winner.PlayerName} won!"); + manager.lr_stats.win(winner,type); + manager.lr_stats.loss(player,type); + manager.end_lr(slot); } @@ -197,6 +200,8 @@ public virtual void grenade_thrown() {} LrState state; + LastRequest.LRType type; + // who are we playing against, set up in create_pair public LRBase? partner; diff --git a/src/LastRequest/LRKnife.cs b/src/LastRequest/LRKnife.cs index 8586dd7..67a8e8d 100644 --- a/src/LastRequest/LRKnife.cs +++ b/src/LastRequest/LRKnife.cs @@ -13,7 +13,7 @@ public class LRKnife : LRBase { - public LRKnife(LastRequest manager,int lr_slot, int player_slot, String choice) : base(manager,"Knife fight",lr_slot,player_slot,choice) + public LRKnife(LastRequest manager,LastRequest.LRType type,int lr_slot, int player_slot, String choice) : base(manager,type,lr_slot,player_slot,choice) { } diff --git a/src/LastRequest/LastRequest.cs b/src/LastRequest/LastRequest.cs index 0b8c308..88aa6c3 100644 --- a/src/LastRequest/LastRequest.cs +++ b/src/LastRequest/LastRequest.cs @@ -136,64 +136,64 @@ void init_lr(LRChoice choice) { case LRType.KNIFE: { - t_lr = new LRKnife(this,slot,choice.t_slot,choice.option); - ct_lr = new LRKnife(this,slot,choice.ct_slot,choice.option); + t_lr = new LRKnife(this,choice.type,slot,choice.t_slot,choice.option); + ct_lr = new LRKnife(this,choice.type,slot,choice.ct_slot,choice.option); break; } case LRType.GUN_TOSS: { - t_lr = new LRGunToss(this,slot,choice.t_slot,choice.option); - ct_lr = new LRGunToss(this,slot,choice.ct_slot,choice.option); + t_lr = new LRGunToss(this,choice.type,slot,choice.t_slot,choice.option); + ct_lr = new LRGunToss(this,choice.type,slot,choice.ct_slot,choice.option); break; } case LRType.DODGEBALL: { - t_lr = new LRDodgeball(this,slot,choice.t_slot,choice.option); - ct_lr = new LRDodgeball(this,slot,choice.ct_slot,choice.option); + t_lr = new LRDodgeball(this,choice.type,slot,choice.t_slot,choice.option); + ct_lr = new LRDodgeball(this,choice.type,slot,choice.ct_slot,choice.option); break; } case LRType.GRENADE: { - t_lr = new LRGrenade(this,slot,choice.t_slot,choice.option); - ct_lr = new LRGrenade(this,slot,choice.ct_slot,choice.option); + t_lr = new LRGrenade(this,choice.type,slot,choice.t_slot,choice.option); + ct_lr = new LRGrenade(this,choice.type,slot,choice.ct_slot,choice.option); break; } case LRType.SHOTGUN_WAR: { - t_lr = new LRShotgunWar(this,slot,choice.t_slot,choice.option); - ct_lr = new LRShotgunWar(this,slot,choice.ct_slot,choice.option); + t_lr = new LRShotgunWar(this,choice.type,slot,choice.t_slot,choice.option); + ct_lr = new LRShotgunWar(this,choice.type,slot,choice.ct_slot,choice.option); break; } case LRType.SCOUT_KNIFE: { - t_lr = new LRScoutKnife(this,slot,choice.t_slot,choice.option); - ct_lr = new LRScoutKnife(this,slot,choice.ct_slot,choice.option); + t_lr = new LRScoutKnife(this,choice.type,slot,choice.t_slot,choice.option); + ct_lr = new LRScoutKnife(this,choice.type,slot,choice.ct_slot,choice.option); break; } case LRType.SHOT_FOR_SHOT: { - t_lr = new LRShotForShot(this,slot,choice.t_slot,choice.option); - ct_lr = new LRShotForShot(this,slot,choice.ct_slot,choice.option); + t_lr = new LRShotForShot(this,choice.type,slot,choice.t_slot,choice.option); + ct_lr = new LRShotForShot(this,choice.type,slot,choice.ct_slot,choice.option); break; } case LRType.MAG_FOR_MAG: { - t_lr = new LRShotForShot(this,slot,choice.t_slot,choice.option,true); - ct_lr = new LRShotForShot(this,slot,choice.ct_slot,choice.option,true); + t_lr = new LRShotForShot(this,choice.type,slot,choice.t_slot,choice.option,true); + ct_lr = new LRShotForShot(this,choice.type,slot,choice.ct_slot,choice.option,true); break; } case LRType.HEADSHOT_ONLY: { - t_lr = new LRHeadshotOnly(this,slot,choice.t_slot,choice.option); - ct_lr = new LRHeadshotOnly(this,slot,choice.ct_slot,choice.option); + t_lr = new LRHeadshotOnly(this,choice.type,slot,choice.t_slot,choice.option); + ct_lr = new LRHeadshotOnly(this,choice.type,slot,choice.ct_slot,choice.option); break; } @@ -256,6 +256,8 @@ public void round_end() public void disconnect(CCSPlayerController? player) { + lr_stats.purge_player(player); + LRBase? lr = find_lr(player); if(lr != null) @@ -898,7 +900,7 @@ public enum LRType NONE, }; - static String[] LR_NAME = { + public static String[] LR_NAME = { "Knife Fight", "Gun toss", "Dodgeball", @@ -927,7 +929,7 @@ internal class LRChoice bool knife_rebel_active = false; LRChoice[] lr_choice = new LRChoice[64]; - LRStats lr_stats = new LRStats(); + public LRStats lr_stats = new LRStats(); public static readonly String LR_PREFIX = $" {ChatColors.Green}[LR]: {ChatColors.White}"; diff --git a/src/LastRequest/ScoutKnife.cs b/src/LastRequest/ScoutKnife.cs index a0e1b78..bb688e2 100644 --- a/src/LastRequest/ScoutKnife.cs +++ b/src/LastRequest/ScoutKnife.cs @@ -13,7 +13,7 @@ public class LRScoutKnife : LRBase { - public LRScoutKnife(LastRequest manager,int lr_slot, int player_slot, String choice) : base(manager,"Scout knife",lr_slot,player_slot,choice) + public LRScoutKnife(LastRequest manager,LastRequest.LRType type,int lr_slot, int player_slot, String choice) : base(manager,type,lr_slot,player_slot,choice) { } diff --git a/src/LastRequest/ShotForShot.cs b/src/LastRequest/ShotForShot.cs index a4adb9c..74c86b5 100644 --- a/src/LastRequest/ShotForShot.cs +++ b/src/LastRequest/ShotForShot.cs @@ -15,7 +15,7 @@ public class LRShotForShot : LRBase { - public LRShotForShot(LastRequest manager,int lr_slot, int player_slot, String choice, bool mag = false) : base(manager,"Shot for shot",lr_slot,player_slot,choice) + public LRShotForShot(LastRequest manager,LastRequest.LRType type,int lr_slot, int player_slot, String choice, bool mag = false) : base(manager,type,lr_slot,player_slot,choice) { mag_for_mag = mag; } diff --git a/src/LastRequest/ShotgunWar.cs b/src/LastRequest/ShotgunWar.cs index a6e6617..5108c5a 100644 --- a/src/LastRequest/ShotgunWar.cs +++ b/src/LastRequest/ShotgunWar.cs @@ -13,7 +13,7 @@ public class LRShotgunWar : LRBase { - public LRShotgunWar(LastRequest manager,int lr_slot, int player_slot, String choice) : base(manager,"Shotgun war",lr_slot,player_slot,choice) + public LRShotgunWar(LastRequest manager,LastRequest.LRType type,int lr_slot, int player_slot, String choice) : base(manager,type,lr_slot,player_slot,choice) { } diff --git a/src/LastRequest/Stats.cs b/src/LastRequest/Stats.cs index d549827..dcd977c 100644 --- a/src/LastRequest/Stats.cs +++ b/src/LastRequest/Stats.cs @@ -26,10 +26,11 @@ public void win(CCSPlayerController? player, LastRequest.LRType type) { var lr_player = lr_player_from_player(player); - if(lr_player != null && type != LastRequest.LRType.NONE) + if(lr_player != null && type != LastRequest.LRType.NONE && player != null && player.is_valid()) { int idx = (int)type; lr_player.win[idx] += 1; + Lib.announce(LastRequest.LR_PREFIX,$"{player.PlayerName} won {LastRequest.LR_NAME[idx]} win {lr_player.win[idx]} : loss {lr_player.loss[idx]}"); } } @@ -37,10 +38,11 @@ public void loss(CCSPlayerController? player, LastRequest.LRType type) { var lr_player = lr_player_from_player(player); - if(lr_player != null && type != LastRequest.LRType.NONE) + if(lr_player != null && type != LastRequest.LRType.NONE && player != null && player.is_valid()) { int idx = (int)type; lr_player.loss[idx] += 1; + Lib.announce(LastRequest.LR_PREFIX,$"{player.PlayerName} lost {LastRequest.LR_NAME[idx]} win {lr_player.win[idx]} : loss {lr_player.loss[idx]}"); } } @@ -61,6 +63,48 @@ public void loss(CCSPlayerController? player, LastRequest.LRType type) return lr_players[slot.Value]; } + + + void print_stats(CCSPlayerController? invoke, CCSPlayerController? player) + { + if(invoke == null || !invoke.is_valid()) + { + return; + } + + var lr_player = lr_player_from_player(player); + + if(lr_player != null && player != null && player.is_valid()) + { + invoke.PrintToChat($"{LastRequest.LR_PREFIX} lr stats for {player.PlayerName}"); + + for(int i = 0; i < LastRequest.LR_SIZE; i++) + { + invoke.PrintToChat($"{LastRequest.LR_PREFIX} {LastRequest.LR_NAME[i]} win {lr_player.win[i]} : loss {lr_player.loss[i]}"); + } + } + } + + public void lr_stats_cmd(CCSPlayerController? player, CommandInfo command) + { + // just do own player for now + print_stats(player,player); + } + + public void purge_player(CCSPlayerController? player) + { + var lr_player = lr_player_from_player(player); + + if(lr_player != null) + { + for(int i = 0; i < LastRequest.LR_SIZE; i++) + { + lr_player.win[i] = 0; + lr_player.loss[i] = 0; + } + } + } + class PlayerStat { public int[] win = new int[LastRequest.LR_SIZE];