mirror of
https://github.com/sudoxnym/habitica-self-host.git
synced 2026-07-31 19:20:25 +00:00
move random-drop inside batch operations
This commit is contained in:
parent
6fd9bfbab4
commit
a6f4e01de7
2 changed files with 29 additions and 20 deletions
|
|
@ -107,6 +107,31 @@ score = (model, taskId, direction, times, batch, cron) ->
|
|||
origStats = _.clone obj.stats
|
||||
updateStats model, { hp, exp, gp }, batch
|
||||
|
||||
###
|
||||
Drops
|
||||
###
|
||||
# 1% chance of getting a pet or meat
|
||||
if direction is 'up' and obj.flags.dropsEnabled and Math.random() < .5
|
||||
if Math.random() < .5
|
||||
drop = randomVal(food)
|
||||
obj.items.food.push drop.name
|
||||
batch.set 'items.food', obj.items.food
|
||||
drop.type = 'Food'
|
||||
drop.dialog = "You've found #{drop.text} Hatching Powder! #{drop.notes}"
|
||||
else
|
||||
drop = randomVal(pets)
|
||||
obj.items.eggs.push drop
|
||||
batch.set 'items.eggs', obj.items.eggs
|
||||
drop.type = 'Egg'
|
||||
drop.dialog = "You've found a #{drop.text} Egg! #{drop.notes}"
|
||||
|
||||
model.set '_drop', drop
|
||||
$('#item-dropped-modal').modal 'show'
|
||||
|
||||
|
||||
###
|
||||
Commit
|
||||
###
|
||||
if commit
|
||||
# newStats / origStats is a glorious hack to trick Derby into seeing the change in model.on(*)
|
||||
newStats = _.clone batch.obj().stats
|
||||
|
|
@ -115,22 +140,6 @@ score = (model, taskId, direction, times, batch, cron) ->
|
|||
# batch.setStats()
|
||||
batch.commit()
|
||||
|
||||
# 1% chance of getting a pet or meat
|
||||
if direction is 'up' and obj.flags.dropsEnabled and Math.random() < .5
|
||||
if Math.random() < .5
|
||||
drop = randomVal(food)
|
||||
user.push 'items.food', drop.name
|
||||
drop.type = 'Food'
|
||||
drop.dialog = "You've found #{drop.text} Hatching Powder! #{drop.notes}"
|
||||
else
|
||||
drop = randomVal(pets)
|
||||
user.push 'items.eggs', drop
|
||||
drop.type = 'Egg'
|
||||
drop.dialog = "You've found a #{drop.text} Egg! #{drop.notes}"
|
||||
|
||||
model.set '_drop', drop
|
||||
$('#item-dropped-modal').modal 'show'
|
||||
|
||||
return delta
|
||||
|
||||
###
|
||||
|
|
|
|||
|
|
@ -56,18 +56,18 @@
|
|||
</div>
|
||||
{#if _feedEgg}
|
||||
<div class='span6 well'>
|
||||
<h3>Feed Your Egg</h3>
|
||||
<h3>Hatch Your Egg</h3>
|
||||
{#if not(_user.items.food)}
|
||||
<p>You don't have any food yet.</p>
|
||||
<p>You don't have any hatching powder yet.</p>
|
||||
{else}
|
||||
<p>What would you like to feed your {_feedEgg.text}?</p>
|
||||
<p>What would you like to sprinkle on your {_feedEgg.text} egg?</p>
|
||||
<form x-bind="submit:feedEgg">
|
||||
<select>
|
||||
{#each _user.items.food as :food}
|
||||
<option>{:food}</option>
|
||||
{/each}
|
||||
</select>
|
||||
<button type=submit>Feed!</button>
|
||||
<button type=submit>Sprinkle</button>
|
||||
</form>
|
||||
{/if}
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Reference in a new issue