From 1fc98d74b9056b0c322a6d7bcf678abfcf74101f Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Mon, 6 Mar 2017 01:02:30 +0100 Subject: [PATCH] =?UTF-8?q?Partially=20implement=20=E2=80=9CSniper=20Duel?= =?UTF-8?q?=E2=80=9D=20achievement?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mods/HUD/mcl_achievements/depends.txt | 1 - mods/HUD/mcl_achievements/init.lua | 9 +++++++++ mods/ITEMS/mcl_throwing/arrow.lua | 12 +++++++++++- mods/ITEMS/mcl_throwing/depends.txt | 1 + mods/ITEMS/mcl_throwing/init.lua | 1 + 5 files changed, 22 insertions(+), 2 deletions(-) diff --git a/mods/HUD/mcl_achievements/depends.txt b/mods/HUD/mcl_achievements/depends.txt index 838538e310..c541f27a13 100644 --- a/mods/HUD/mcl_achievements/depends.txt +++ b/mods/HUD/mcl_achievements/depends.txt @@ -4,5 +4,4 @@ mcl_core mcl_cake mcl_mobitems mcl_flowerpots -mcl_dispensers intllib? diff --git a/mods/HUD/mcl_achievements/init.lua b/mods/HUD/mcl_achievements/init.lua index 7dc760531f..e65e098e33 100644 --- a/mods/HUD/mcl_achievements/init.lua +++ b/mods/HUD/mcl_achievements/init.lua @@ -143,10 +143,19 @@ awards.register_achievement("mcl:onARail", { icon = "default_rail.png", }) +-- Triggered in mcl_throwing +awards.register_achievement("mcl:snipeSkeleton", { + title = S("Sniper Duel"), + -- TODO: This achievement should be for killing, not hitting + description = S("Hit a skeleton, wither skeleton or stray by bow and arrow from a distance of at least 50 meters."), + icon = "mcl_throwing_bow.png", +}) + -- NON-PC ACHIEVEMENTS (XBox, Pocket Edition, etc.) awards.register_achievement("mcl:n_placeDispenser", { title = S("Dispense With This"), + description = S("Place a dispenser."), icon = "mcl_dispensers_dispenser_front_horizontal.png", trigger = { type = "place", diff --git a/mods/ITEMS/mcl_throwing/arrow.lua b/mods/ITEMS/mcl_throwing/arrow.lua index 101ab810ed..a2924b7a42 100644 --- a/mods/ITEMS/mcl_throwing/arrow.lua +++ b/mods/ITEMS/mcl_throwing/arrow.lua @@ -40,6 +40,7 @@ local THROWING_ARROW_ENTITY={ _timer=0, _lastpos={}, + _startpos=nil, _damage=1, -- Damage on impact _shooter=nil, -- ObjectRef of player or mob who shot it } @@ -53,11 +54,20 @@ THROWING_ARROW_ENTITY.on_step = function(self, dtime) local objs = minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 2) for k, obj in pairs(objs) do if obj:get_luaentity() ~= nil then - if obj ~= self._shooter and obj:get_luaentity().name ~= "mcl_throwing:arrow_entity" and obj:get_luaentity().name ~= "__builtin:item" then + local entity_name = obj:get_luaentity().name + if obj ~= self._shooter and entity_name ~= "mcl_throwing:arrow_entity" and entity_name ~= "__builtin:item" then obj:punch(self.object, 1.0, { full_punch_interval=1.0, damage_groups={fleshy=self._damage}, }, nil) + + -- Achievement for hitting skeleton, wither skeleton or stray (TODO) with an arrow at least 50 meters away + -- TODO: This achievement should be given for the kill, not just a hit + if self._shooter and self._shooter:is_player() and vector.distance(pos, self._startpos) >= 50 then + if (entity_name == "mobs_mc:skeleton" or entity_name == "mobs_mc:skeleton2") then + awards.unlock(self._shooter:get_player_name(), "mcl:snipeSkeleton") + end + end self.object:remove() end elseif obj ~= self._shooter then diff --git a/mods/ITEMS/mcl_throwing/depends.txt b/mods/ITEMS/mcl_throwing/depends.txt index 315237e07b..567d5229ef 100644 --- a/mods/ITEMS/mcl_throwing/depends.txt +++ b/mods/ITEMS/mcl_throwing/depends.txt @@ -1 +1,2 @@ mcl_core +mcl_achievements diff --git a/mods/ITEMS/mcl_throwing/init.lua b/mods/ITEMS/mcl_throwing/init.lua index 7200f0b757..9f7fe64dbc 100644 --- a/mods/ITEMS/mcl_throwing/init.lua +++ b/mods/ITEMS/mcl_throwing/init.lua @@ -23,6 +23,7 @@ mcl_throwing.shoot_arrow = function(arrow_item, pos, dir, yaw, shooter, power, d local le = obj:get_luaentity() le._shooter = shooter le._damage = damage + le._startpos = pos minetest.sound_play("mcl_throwing_bow_shoot", {pos=pos}) if shooter ~= nil then if obj:get_luaentity().player == "" then