void ResolveProperty(Property prop, int value, int target) { switch (prop) { // --- Resource --- // case Property.Health: if (value < 0) { HealthLostEvent?.Invoke(target, -value); } else { HealthGainedEvent?.Invoke(target, value); } break; // --- Stat --- // case Property.Str: case Property.Dex: case Property.Int: case Property.Fire: case Property.Nature: case Property.Water: case Property.Wind: Stat stat = prop.ToStat(); StatChangedEvent?.Invoke(target, stat, value, Math.Abs(value * 2)); break; default: UISystem.Message(String.Format("Item effect not implemented: {0} ({1})", prop.ToString(), value)); break; } }
/// <summary> /// Sets a given stat belonging to the actor to a specific value. This triggers StatChangedEvent on the server. /// </summary> /// <param name="_name"></param> /// <param name="_val"></param> public void SetStat(string _name, int _val) { if (entity.isOwner) { //PropertyInfo property = GetType().GetProperty(_name); Debug.Log(_name + " set to " + _val); // Get the actor's stat set. Then create a Bolt Event with the name of the stat to be change and the value to change it by. // Will catch NulLReferenceException if an invalid _name is given. try { Bolt.NetworkArray_Objects <BoltActorStat> statset = state.BoltActorStatset.Statset; IEnumerable <BoltActorStat> query = from stat in statset where stat.StatName == _name select stat; query.First().StatValue += _val; StatChangedEvent evnt = StatChangedEvent.Create(entity); evnt.StatName = _name; evnt.StatMod = _val; evnt.Send(); } catch (System.NullReferenceException nre) { Debug.LogError(nre); } } }
//Misc methods private void ChangeStat(ref double stat, double newVal, StatChangedEvent EventMethod) { //Change the stat. double oldVal = stat; stat = newVal; //Send the event if (EventMethod != null) { EventMethod(this, oldVal, stat); } }
/* * NETWORK EVENTS */ public override void OnEvent(StatChangedEvent evnt) { Debug.LogWarning("Stat changed event called."); }
private void DoStatChanged(object source, StatChangedEvent e) { this.OnStatChanged(this, e); }