From 4485d226e80b577b4a9fdf9c1804a7ca89ffbac4 Mon Sep 17 00:00:00 2001 From: Daniel Saewitz Date: Wed, 13 Mar 2013 11:37:06 -0400 Subject: [PATCH] 1% chance on every score to get an item --- src/app/scoring.coffee | 18 +++++++++++++++++- views/app/pets.html | 10 +++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/app/scoring.coffee b/src/app/scoring.coffee index 4a65c4544b..4c6cc68525 100644 --- a/src/app/scoring.coffee +++ b/src/app/scoring.coffee @@ -1,10 +1,11 @@ async = require 'async' moment = require 'moment' _ = require 'underscore' -helpers = require './helpers' +{ randomProp } = helpers = require './helpers' browser = require './browser' character = require './character' items = require './items' +{ pets, food } = items.items algos = require './algos' MODIFIER = algos.MODIFIER # each new level, armor, weapon add 2% modifier (this mechanism will change) @@ -105,6 +106,21 @@ score = (model, taskId, direction, times, batch, cron) -> batch.set "#{taskPath}.value", taskObj.value origStats = _.clone obj.stats updateStats model, {hp: hp, exp: exp, gp: gp}, batch + + # 1% chance of getting a pet or meat + if Math.random() < .01 + if Math.random() < .5 + drop = randomProp(food) + user.push 'items.food', drop.name + drop.type = 'food' + else + drop = randomProp(pets) + user.push 'items.eggs', drop + drop.type = 'egg' + + model.set '_drop', drop + $('#itemDropped-modal').show() + if commit # newStats / origStats is a glorious hack to trick Derby into seeing the change in model.on(*) newStats = _.clone batch.obj().stats diff --git a/views/app/pets.html b/views/app/pets.html index 24a040da48..9c025105d3 100644 --- a/views/app/pets.html +++ b/views/app/pets.html @@ -6,4 +6,12 @@ <@footer> - \ No newline at end of file + + +

An item has dropped!

+

Here's your first {_drop.type} – {_drop.text}!

+

{_drop.notes}

+ <@footer> + + +