From f6b3a6efb8bd2ff4a39fc4a2945e018b779f87cf Mon Sep 17 00:00:00 2001 From: Sven Eberhardt Date: Sun, 21 Aug 2016 15:17:51 -0400 Subject: [PATCH] Add magic wand as an editor-assignable usage item --- .../Helpers.ocd/UserAction.ocd/Script.c | 13 ++- .../UserAction.ocd/StringTblDE.txt | 2 + .../UserAction.ocd/StringTblUS.txt | 2 + .../Tools.ocd/MagicWand.ocd/DefCore.txt | 14 ++++ .../Tools.ocd/MagicWand.ocd/Script.c | 79 +++++++++++++++++++ .../Tools.ocd/MagicWand.ocd/StringTblDE.txt | 6 ++ .../Tools.ocd/MagicWand.ocd/StringTblUS.txt | 6 ++ 7 files changed, 119 insertions(+), 3 deletions(-) create mode 100644 planet/Objects.ocd/Items.ocd/Tools.ocd/MagicWand.ocd/DefCore.txt create mode 100644 planet/Objects.ocd/Items.ocd/Tools.ocd/MagicWand.ocd/Script.c create mode 100644 planet/Objects.ocd/Items.ocd/Tools.ocd/MagicWand.ocd/StringTblDE.txt create mode 100644 planet/Objects.ocd/Items.ocd/Tools.ocd/MagicWand.ocd/StringTblUS.txt diff --git a/planet/Objects.ocd/Helpers.ocd/UserAction.ocd/Script.c b/planet/Objects.ocd/Helpers.ocd/UserAction.ocd/Script.c index 10b77970a..177733818 100644 --- a/planet/Objects.ocd/Helpers.ocd/UserAction.ocd/Script.c +++ b/planet/Objects.ocd/Helpers.ocd/UserAction.ocd/Script.c @@ -356,6 +356,7 @@ func Definition(def) Offset = new Evaluator.Offset { EditorHelp="$PositionOffsetOffsetHelp$", Priority=21 } } } ); AddEvaluator("Position", nil, "$ObjectPosition$", "$ObjectPositionHelp$", "object_position", [def, def.EvalPositionObject], { Object={Function="triggering_object"} }, new Evaluator.Object { EditorHelp="$ObjectPositionObjectHelp$" }, "Object"); + AddEvaluator("Position", nil, "$LastUsePosition$", "$LastUsePositionHelp$", "use_position", [def, def.EvalPos_LastUse]); AddEvaluator("Position", "$RandomPosition$", "$RandomRectAbs$", "$RandomRectAbsHelp$", "random_pos_rect_abs", [def, def.EvalPos_RandomRect, false], def.GetDefaultRect, { Type="rect", Name="$Rectangle$", Relative=false, Color=0xffff00 }, "Area"); AddEvaluator("Position", "$RandomPosition$", "$RandomRectRel$", "$RandomRectRelHelp$", "random_pos_rect_rel", [def, def.EvalPos_RandomRect, true], { Area=[-30,-30,60,60] }, { Type="rect", Name="$Rectangle$", Relative=true, Color=0x00ffff }, "Area"); AddEvaluator("Position", "$RandomPosition$", "$RandomCircleAbs$", "$RandomCircleAbsHelp$", "random_pos_circle_abs", [def, def.EvalPos_RandomCircle, false], def.GetDefaultCircle, { Type="circle", Name="$Circle$", Relative=false, CanMoveCenter=true, Color=0xff00ff }, "Area"); @@ -497,7 +498,7 @@ public func EvaluateValue(string eval_type, proplist props, proplist context) return cb[0]->Call(cb[1], props, context, cb[2]); } -public func EvaluateAction(proplist props, object action_object, object triggering_object, int triggering_player, string progress_mode, bool allow_parallel, finish_callback) +public func EvaluateAction(proplist props, object action_object, object triggering_object, int triggering_player, string progress_mode, bool allow_parallel, finish_callback, array position) { // No action if (!props) if (finish_callback) return action_object->Call(finish_callback); else return; @@ -525,7 +526,7 @@ public func EvaluateAction(proplist props, object action_object, object triggeri // Prevent duplicate parallel execution if (!allow_parallel && (context.hold && !context.suspended)) return false; // Init context settings - context->InitContext(action_object, triggering_player, triggering_object, props, finish_callback); + context->InitContext(action_object, triggering_player, triggering_object, props, finish_callback, position); // Execute action EvaluateValue("Action", props, context); FinishAction(context); @@ -1134,6 +1135,8 @@ private func EvalPositionObject(proplist props, proplist context) return [0,0]; // undefined object: Position is 0/0 default } +private func EvalPos_LastUse(proplist props, proplist context) { return context.position; } + private func EvalPos_RandomRect(proplist props, proplist context, bool relative) { // Constant random distribution in rectangle @@ -1253,7 +1256,7 @@ public func Initialize() return true; } -public func InitContext(object action_object, int triggering_player, object triggering_object, proplist props, finish_callback) +public func InitContext(object action_object, int triggering_player, object triggering_object, proplist props, finish_callback, position) { // Determine triggering player+objects var triggering_clonk; @@ -1273,11 +1276,15 @@ public func InitContext(object action_object, int triggering_player, object trig triggering_object = triggering_clonk; else if (triggering_object->~IsClonk()) triggering_clonk = triggering_object; + // Position default + if (!position && triggering_object) + position = [triggering_object->GetX(), triggering_object->GetY()]; // Init context settings this.action_object = action_object; this.triggering_object = triggering_object; this.triggering_clonk = triggering_clonk; this.triggering_player = triggering_player; + this.position = position; this.root_action = props; this.suspended = false; this.finish_callback = finish_callback; diff --git a/planet/Objects.ocd/Helpers.ocd/UserAction.ocd/StringTblDE.txt b/planet/Objects.ocd/Helpers.ocd/UserAction.ocd/StringTblDE.txt index 6d0d3b03a..92e0d833a 100644 --- a/planet/Objects.ocd/Helpers.ocd/UserAction.ocd/StringTblDE.txt +++ b/planet/Objects.ocd/Helpers.ocd/UserAction.ocd/StringTblDE.txt @@ -342,3 +342,5 @@ Smoke=Rauch Sphere=Kreis StarFlash=Stern StarSpark=Sonne +LastUsePosition=Aktivierungsposition +LastUsePositionHelp=Fuer aktivierbare Gegenstaende wie den Zauberstab: Mausposition, an der der Spieler das Objekt aktiviert hat. diff --git a/planet/Objects.ocd/Helpers.ocd/UserAction.ocd/StringTblUS.txt b/planet/Objects.ocd/Helpers.ocd/UserAction.ocd/StringTblUS.txt index 54f603510..882ad3ce7 100644 --- a/planet/Objects.ocd/Helpers.ocd/UserAction.ocd/StringTblUS.txt +++ b/planet/Objects.ocd/Helpers.ocd/UserAction.ocd/StringTblUS.txt @@ -341,3 +341,5 @@ Smoke=Smoke Sphere=Sphere StarFlash=Star StarSpark=Sun +LastUsePosition=Activation position +LastUsePositionHelp=Valid for activated items such as the magic wand: Mouse position where the player activated the item. diff --git a/planet/Objects.ocd/Items.ocd/Tools.ocd/MagicWand.ocd/DefCore.txt b/planet/Objects.ocd/Items.ocd/Tools.ocd/MagicWand.ocd/DefCore.txt new file mode 100644 index 000000000..9ccdff539 --- /dev/null +++ b/planet/Objects.ocd/Items.ocd/Tools.ocd/MagicWand.ocd/DefCore.txt @@ -0,0 +1,14 @@ +[DefCore] +id=MagicWand +Version=8,0 +Category=C4D_Object +Width=3 +Height=16 +Offset=-1,-8 +Vertices=2 +VertexX=0,0 +VertexY=-7,7 +VertexFriction=50,50 +Value=100 +Mass=20 +Rotate=1 diff --git a/planet/Objects.ocd/Items.ocd/Tools.ocd/MagicWand.ocd/Script.c b/planet/Objects.ocd/Items.ocd/Tools.ocd/MagicWand.ocd/Script.c new file mode 100644 index 000000000..81cdb2dba --- /dev/null +++ b/planet/Objects.ocd/Items.ocd/Tools.ocd/MagicWand.ocd/Script.c @@ -0,0 +1,79 @@ +/** + Magic wand + Item to be made magical with editor actions/ + + @author Sven2 + --*/ + +public func Initialize() +{ + // We don't have nice graphics yet :( + SetGraphics(nil, Torch); +} + +public func Hit() +{ + Sound("Hits::Materials::Wood::WoodHit?"); +} + +public func ControlUse(object clonk, int x, int y) +{ + // No clonk? + if (!clonk) return false; + // Cooldown? + if (last_use_frame != nil) + if (FrameCounter() - last_use_frame < cooldown) + { + PlayerMessage(clonk->GetController(), "$NoUseCooldown$"); + Sound("UI::Error", true, nil, clonk->GetController()); + return true; + } + // Action go! + UserAction->EvaluateAction(use_action, this, clonk, nil, nil, action_allow_parallel, nil, [x+GetX(), y+GetY()]); + last_use_frame = FrameCounter(); + return true; +} + +public func SetUseAction(new_action) +{ + use_action = new_action; + return true; +} + +public func SetCooldown(int new_cooldown) +{ + cooldown = new_cooldown; + return true; +} + + +/*-- Display --*/ + +public func GetCarryMode(object clonk, bool idle, bool nohand) +{ + if (idle || nohand) + return CARRY_Back; + + return CARRY_Spear; +} + +func Definition(def) +{ + // Display + SetProperty("PictureTransformation", Trans_Mul(Trans_Translate(2500, -1500, 0), Trans_Rotate(-30, 0, 0, 1)), def); + // Actions + if (!def.EditorProps) def.EditorProps = {}; + def.EditorProps.use_action = new UserAction.Prop { Name="$MagicAction$", Priority=100, Set="SetUseAction", Save="Action", Priority=100 }; + def.EditorProps.cooldown = { Name="$Cooldown$", Type="int", EditorHelp="$CooldownHelp$", Set="SetCooldown", Save="Cooldown", Min=0 }; + def.EditorProps.action_allow_parallel = UserAction.PropParallel; +} + +/*-- Properties --*/ + +local last_use_frame; +local Name = "$Name$"; +local Description = "$Description$"; +local Collectible = true; +local Components = {Wood = 1, Diamond = 1}; +local use_action = nil, action_allow_parallel = false; +local cooldown = 40; \ No newline at end of file diff --git a/planet/Objects.ocd/Items.ocd/Tools.ocd/MagicWand.ocd/StringTblDE.txt b/planet/Objects.ocd/Items.ocd/Tools.ocd/MagicWand.ocd/StringTblDE.txt new file mode 100644 index 000000000..ca9aaa928 --- /dev/null +++ b/planet/Objects.ocd/Items.ocd/Tools.ocd/MagicWand.ocd/StringTblDE.txt @@ -0,0 +1,6 @@ +Name=Zauberstab +Description=Enthaellt verborgene Kraefte. +NoUseCooldown=Abklingzeit noch nicht verstrichen +MagicAction=Zauberaktion +Cooldown=Abklingzeit +CooldownHelp=Minimalzeit zwischen zwei Zaubern diff --git a/planet/Objects.ocd/Items.ocd/Tools.ocd/MagicWand.ocd/StringTblUS.txt b/planet/Objects.ocd/Items.ocd/Tools.ocd/MagicWand.ocd/StringTblUS.txt new file mode 100644 index 000000000..3f17d4b0f --- /dev/null +++ b/planet/Objects.ocd/Items.ocd/Tools.ocd/MagicWand.ocd/StringTblUS.txt @@ -0,0 +1,6 @@ +Name=Magic wand +Description=Contains hidden powers. +NoUseCooldown=Cooldown hasn't passed yet. +MagicAction=Magic action +Cooldown=Cooldown time +CooldownHelp=Minimal time in frames between two spellcast actions.