You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Gives each player a random skill every round. Configurable via config.
Creating A Skill
In order to create a new skill, do this:
Clone the repository
Go into src\skills\
Create a file with your skill name e.g Jetpack.cs
Here's a skill example:
Info
You already have acces to Core and Localizer from the BaseSkill class.
You also have overrides voids like OnButtonReleased, OnButtonPressed, etc.
To learn more just check the other skils i've made.
namespaceSW2_RandomSkills;publicclassRandomHealthSkill(ILocalizerlocalizer,ISwiftlyCorecore):BaseSkill(localizer,core){publicoverrideSkillTypeType=>SkillType.RandomHealth;// Set the skill typepublicoverridestringName=>"Random Health";// Skill Name, this will be shown in rollingprivateRandom_random=new();privatestring_randomHealthValues=null!;// we will get this variable value from config.protectedoverridestringGetDefaultDescription(){return"Gives you a random amount of health!";}publicoverridevoidInitialize(SkillConfigconfig){base.Initialize(config);_randomHealthValues=GetParameter("RandomHealthValues","100,125,200,255,300");// get the variable values from config and set default values as a fallback.}publicoverridevoidApply(IPlayerplayer)// this is called OnPlayerSpawn{string[]healths=_randomHealthValues.Split(",",StringSplitOptions.RemoveEmptyEntries);stringrandomHealthSelected=healths[_random.Next(healths.Count())];if(!int.TryParse(randomHealthSelected,outintrandomHealth)){SW2_RandomSkills.Core.Logger.LogInformation($"Invalid random health value at Random Health skill. Please enter an integer.");return;}player.SetHealth(randomHealth);player.SendChat(Localizer["prefix"]+Localizer["random_health.given",randomHealth]);}}
After you created your own skill, go into src/SW2-RandomSkills.cs and register it like this OnLoad:
This is the base skill class. You can see each feature you can use it in your own skill class from here.
publicabstractclassBaseSkill{protectedreadonlyILocalizerLocalizer=null!;protectedreadonlyISwiftlyCoreCore=null!;protectedBaseSkill(ILocalizerlocalizer,ISwiftlyCorecore){Localizer=localizer;Core=core;}publicabstractSkillTypeType{get;}publicabstractstringName{get;}publicvirtualstringDescription{get{stringskillKey=Name.ToLower().Replace(" ","_");stringkey=$"{skillKey}.description";if(Localizer!=null){try{returnGetLocalizedDescription(key);}catch{returnGetDefaultDescription();}}returnGetDefaultDescription();}}protectedvirtualobject[]GetDescriptionParameters(){returnArray.Empty<object>();}protectedstringGetLocalizedDescription(stringkey){try{varparameters=GetDescriptionParameters();if(parameters.Length>0){try{stringresult=Localizer![key,parameters];returnresult;}catch(Exception){returnLocalizer![key];}}stringsimpleResult=Localizer![key];returnsimpleResult;}catch(Exception){returnGetDefaultDescription();}}protectedabstractstringGetDefaultDescription();protectedDateTimeLastActivation{get;set;}=DateTime.MinValue;protectedSkillConfigConfig{get;privateset;}=new();protectedstringGetActivationKey(){returnConfig.ActivationKey??"";}publicvirtualvoidInitialize(SkillConfigconfig){Config=config;}publicvirtualvoidOnButtonPressed(IPlayerplayer,GameButtonFlagsbutton){}publicvirtualvoidOnButtonReleased(IPlayerplayer,GameButtonFlagsbutton){}publicvirtualvoidOnButtonHeld(IPlayerplayer,GameButtonFlagsbutton){}publicvirtualvoidOnActivationButtonPressed(IPlayerplayer){}publicvirtualvoidOnActivationButtonReleased(IPlayerplayer){}publicvirtualvoidOnActivationButtonHeld(IPlayerplayer){}publicvirtualvoidOnTick(IPlayerplayer,floatdeltaTime){}protectedboolIsOnCooldown(){if(Config.Cooldown<=0)returnfalse;return(DateTime.Now-LastActivation).TotalSeconds<Config.Cooldown;}protectedfloatGetCooldownLeft(){if(Config.Cooldown<=0)return0;varelapsed=(float)(DateTime.Now-LastActivation).TotalSeconds;returnMath.Max(0,Config.Cooldown-elapsed);}protectedvoidStartCooldown(){LastActivation=DateTime.Now;}publicabstractvoidApply(IPlayerplayer);publicvirtualvoidRemove(IPlayerplayer){}protectedTGetParameter<T>(stringkey,TdefaultValue){if(Config.Parameters.TryGetValue(key,outobject?value)){if(value==null)returndefaultValue;try{if(valueisTtypedValue)returntypedValue;return(T)Convert.ChangeType(value,typeof(T))!;}catch(Exceptionex){SW2_RandomSkills.Core.Logger.LogError($"Failed to convert parameter '{key}' from {value.GetType().Name} to {typeof(T).Name}: {ex.Message}. Using default value.");returndefaultValue;}}returndefaultValue;}}