4 using System.Collections.Generic;
 
   11 [AddComponentMenu(
"Liberi/Character")]
 
   14     public bool IsSkillReady
 
   18             return CanUseSkill && _energy >= 1f;
 
   26             int index = _activePersonaIndex.LastValue;
 
   28             if (index < 0 || index >= Personas.Length)
 
   31             return Personas[index];
 
   35     public string ActivePersonaID
 
   39             var activePersona = this.ActivePersona;
 
   41             if (activePersona == null)
 
   44             return activePersona.
ID;
 
   50         get { 
return _isTurbo.LastValue; }
 
   62         get { 
return _energy; }
 
   65     const float _personaChangeCooldown = .5f;
 
   68     public bool CanUseSkill = 
true;
 
   69     public bool CanChargeEnergy = 
true;
 
   73     public float BotTurboWarmup = 60f;
 
   75     Timeline<int> _activePersonaIndex;
 
   76     Timeline<bool> _isTurbo;
 
   77     Timeline<bool> _skillUses;
 
   83         _activePersonaIndex = 
Sync.CreateDiscreteState<
int>();
 
   84         _isTurbo = 
Sync.CreateDiscreteState<
bool>();
 
   85         _skillUses = 
Sync.CreateEvent<
bool>();
 
   87         foreach (var trait 
in Traits)
 
   89             trait.Character = 
this;
 
   92         foreach (var persona 
in Personas)
 
   94             persona.Character = 
this;
 
   98     void OnSpawn (
UJeli details)
 
  100         _activePersonaIndex.EntryPassed += OnActivePersonaIndexMessage;
 
  101         _isTurbo.EntryPassed += OnTurboMessage;
 
  102         _skillUses.EntryPassed += OnSkillUseMessage;
 
  106             var characterProfile = Game.GetPlayerProfile(
Sync.
GetOwner(
this)).GetCharacter(name);   
 
  110                 if (characterProfile != null)
 
  111                     SetActivePersona(characterProfile.LastActivePersonaID);
 
  113                 StartCoroutine(UpdateHumanPersonaAsync());
 
  114                 StartCoroutine(UpdateHumanEnergyAsync());
 
  115                 StartCoroutine(UpdateHumanTurboAsync());
 
  119                 foreach (var trait 
in Traits)
 
  122                     characterProfile.TraitPoints.TryGetValue(trait.ID, out traitPoints);
 
  123                     trait.Points = traitPoints;
 
  131                 UJeli personaJeli = details[
"Persona"];
 
  133                 SetActivePersona(personaJeli.Value);
 
  135                 StartCoroutine(UpdateBotEnergyAsync());
 
  136                 StartCoroutine(UpdateBotTurboAsync());
 
  139             UJeli traitsDetail = details[
"Traits"];
 
  141             if (traitsDetail != null)
 
  143                 foreach (var trait 
in Traits)
 
  145                     UJeli traitDetail = traitsDetail[trait.ID];
 
  147                     if (traitDetail != null)
 
  148                         trait.Points = traitDetail.IntValue;
 
  156         return Traits.FirstOrDefault(t => t.ID == traitId);
 
  159     public Persona GetPersona (
string personaId)
 
  161         return Personas.FirstOrDefault(p => p.ID == personaId);
 
  164     public Persona GetPreviousPersona ()
 
  166         return Personas[(_activePersonaIndex.LastValue + Personas.Length - 1) % Personas.Length];
 
  169     public Persona GetNextPersona ()
 
  171         return Personas[(_activePersonaIndex.LastValue + 1) % Personas.Length];
 
  174     public void CyclePreviousPersona ()
 
  176         SetActivePersona(GetPreviousPersona());
 
  179     public void CycleNextPersona ()
 
  181         SetActivePersona(GetNextPersona());
 
  184     public void SetActivePersona (
Persona persona)
 
  186         SetActivePersona(Array.IndexOf(Personas, persona));
 
  189     public void SetActivePersona (
string personaId)
 
  191         SetActivePersona(Array.FindIndex(Personas, p => p.
ID == personaId));
 
  194     private void SetActivePersona (
int personaIndex)
 
  201         if (personaIndex != -1)
 
  204             _activePersonaIndex[0] = personaIndex;
 
  206         else _activePersonaIndex[0] = 0;
 
  209     public void UseSkill ()
 
  211         if (!this.IsSkillReady)
 
  217         _skillUses[0] = 
true;
 
  221     void OnActivePersonaIndexMessage (Timeline<int> timeline, TimelineEntry<int> entry)
 
  226     void OnTurboMessage (Timeline<bool> timeline, TimelineEntry<bool> entry)
 
  233     void OnSkillUseMessage (Timeline<bool> timeline, TimelineEntry<bool> entry)
 
  238     private IEnumerator UpdateHumanPersonaAsync ()
 
  244                 var activePersona = this.ActivePersona;
 
  246                 if (activePersona != null)
 
  248                     if (activePersona.AutoFireSkill)
 
  261             if (_activePersonaIndex.LastValueDuration >= _personaChangeCooldown)
 
  266                     CyclePreviousPersona();
 
  273     private IEnumerator UpdateHumanEnergyAsync ()
 
  279                 Persona activePersona = this.ActivePersona;
 
  281                 if (activePersona != null)
 
  285                         float prevEnergy = _energy;
 
  286                         _energy = Mathf.Min(1, _energy + 
Controls.
Power / activePersona.SkillChargeTime * Time.deltaTime);
 
  288                         if (_energy == 1 && prevEnergy != 1)
 
  289                             this.PlayPooledSound(
"get_action");
 
  291                     else _energy = Mathf.Max(0, _energy - 1 / activePersona.SkillChargeTime * Time.deltaTime);
 
  301     private IEnumerator UpdateBotEnergyAsync ()
 
  307                 Persona activePersona = this.ActivePersona;
 
  309                 if (activePersona != null)
 
  311                     _energy += 1 / activePersona.SkillChargeTime * Time.deltaTime;
 
  321     private IEnumerator UpdateHumanTurboAsync ()
 
  325             if (_isTurbo.LastValue)
 
  329                     if (_isTurbo.LastValue)
 
  339                     if (!_isTurbo.LastValue)
 
  350     private IEnumerator UpdateBotTurboAsync ()
 
  352         yield 
return new WaitForSeconds(Mathf.Max(0f, BotTurboWarmup + 
UnityEngine.Random.Range(-15f, 15f)));
 
static float Power
Returns an abstract power value in the range [0 ... 1]. 
 
A visual representation of HeartRate and Character.Energy. 
 
static bool IsClient
Gets whether or not this peer is a client. 
 
static bool IsClientOwned(GameObject go)
Gets whether or not the given object is owned by a client. 
 
static bool GetAction(ControlsAction action)
Returns the current state of an action. 
 
string ID
String ID of the persona. 
 
Heart class. Allows for heart rate queries and heart rate injection from devices. ...
 
static void RegisterEnergyProvider(Character provider)
Register an instance of a Character (usually the player's local avatar's Character component) to act ...
 
static void SendEnabledMessage(GameObject go, string message, params object[] args)
Invokes a method on all enabled scripts in the GameObject. 
 
static bool IsLocal(GameObject go)
Gets whether or not the given object is owned by the local peer. 
 
static bool GetActionDown(ControlsAction action)
Checks if the given action has just been pressed down. 
 
(Deprecated) Descibes a trait for a character. 
 
static int GetOwner(GameObject go)
Gets the owner peer index of a given object. 
 
Avatar character management component. In charge of personas, skills and buffs. 
 
Class for managing study-related game components. 
 
static HeartTier Tier
Gets the current heart tier. 
 
Unity version of Jeli markup class. 
 
static void LogEvent(Enum eventType, params object[] args)
Log a game event. 
 
This class server two main functions: 1) As a MonoBehaviour, it allows for network synchronization of...
 
Controls class. Allows for controls queries and controls injection from devices. 
 
Descibes a persona for an avatar character.