public EventEntry GetEntry (IBehaviourContext character) { if (this.SourceNode == null) return defaultEntry; EventEntry foundEntry; if (ContextCahce == null) ContextCahce = new Dictionary<IBehaviourContext, EventEntry> (); bool result = ContextCahce.TryGetValue (character, out foundEntry); EventOutput sourceOutput = (EventOutput)SourceSocket; EventEntry connectionEntry = sourceOutput.GetEntry (character); if (!result) { foundEntry = new EventEntry (); connectionEntry.OnEventFired += () => { if (foundEntry != null) foundEntry.OnEventFired (); }; ContextCahce.Add (character, foundEntry); } return foundEntry; }
public void TryUse(ItemSurrogate context, RPGCharacter character) { ConnectionEntry <int> manaCostInput = ManaCost.GetEntry(context); ConnectionEntry <int> quantityCostInput = QuantityCost.GetEntry(context); EventEntry onActivateOutput = OnActivate.GetEntry(context); if (CanCharacterUse(context, character)) { context.owner.Value.States.CurrentMana.Value -= manaCostInput.Value; context.Quantity -= quantityCostInput.Value; onActivateOutput.OnEventFired(); AudioManager.Play(ActivateSound); } }