public Item(ItemDefinition itemDef) { if (itemDef == null) { Logger.LogEvent("Null item definition!", LogTypes.ERROR, Environment.StackTrace); this.Name = "Null"; this.Sprite = new Sprite("nullItem"); return; } this.Name = itemDef.Descriptor.Name; this.Sprite = new Sprite(itemDef.Descriptor.TexturePath); this.Stackable = itemDef.Descriptor.Stackable; this.ItemType = itemDef.Descriptor.ItemType; this.SlotType = itemDef.Descriptor.SlotType; this.Strength = itemDef.Descriptor.Strength; this.Intelligence = itemDef.Descriptor.Intelligence; this.Dexterity = itemDef.Descriptor.Dexterity; this.Defence = itemDef.Descriptor.Defence; this.Health = itemDef.Descriptor.Health; this.BehaviorDefinition = itemDef.BehaviorDefinition; itemDef.Descriptor.DefinitionChanged += ItemDescriptor_DefinitionChanged; this.BehaviorDefinition.OnCreated?.Invoke(new ScriptActionArgs(this)); }
private void InitalizeHooks() { this.BehaviorDefinition = new ItemBehaviorDefinition(); foreach (var pair in this.Descriptor.Scripts) { string scriptActionHook = pair.Key; string scriptContent = pair.Value; Script script = Engine.Services.Get <ScriptManager>().CreateScriptFromSource(scriptContent); switch (scriptActionHook) { case "OnAcquired": BehaviorDefinition.OnAcquired = new Action <ServerArgs>((args) => { script.Invoke("on_acquired", args); } ); break; case "OnCreated": BehaviorDefinition.OnCreated = new Action <ServerArgs>((args) => { script.Invoke("on_created", args); } ); break; case "OnDropped": BehaviorDefinition.OnDropped = new Action <ServerArgs>((args) => { script.Invoke("on_dropped", args); } ); break; case "OnEquip": BehaviorDefinition.OnEquip = new Action <ServerArgs>((args) => { script.Invoke("on_equip", args); } ); break; case "OnUse": BehaviorDefinition.OnUse = new Action <ServerArgs>((args) => { script.Invoke("on_use", args); } ); break; } } }
private void InitalizeHooks() { this.BehaviorDefinition = new ItemBehaviorDefinition(); foreach (var pair in this.Descriptor.Scripts) { string scriptActionHook = pair.Key; string scriptContent = pair.Value; Script script = new Script(scriptContent, false); switch (scriptActionHook) { case "OnAcquired": BehaviorDefinition.OnAcquired = new ScriptAction( (args => { script.GetFunction("OnAcquired").Call(args); } )); break; case "OnCreated": BehaviorDefinition.OnCreated = new ScriptAction( (args => { script.GetFunction("OnCreated").Call(args); } )); break; case "OnDropped": BehaviorDefinition.OnDropped = new ScriptAction( (args => { script.GetFunction("OnDropped").Call(args); } )); break; case "OnEquip": BehaviorDefinition.OnEquip = new ScriptAction( (args => { script.GetFunction("OnEquip").Call(args); } )); break; case "OnUse": BehaviorDefinition.OnUse = new ScriptAction((args => { script.GetFunction("OnUse").Call(args); } )); break; } } }
private void ItemDescriptor_DefinitionChanged(object sender, System.EventArgs e) { this.BehaviorDefinition = ((ItemDefinition)sender).BehaviorDefinition; }