mirror of
https://github.com/sudoxnym/habitica.git
synced 2026-05-20 04:38:55 +00:00
add unbreakable special items, so we can add special-event gear which users can buy during a certain period of time, but which they can't lose on death. Starting with party-hats
This commit is contained in:
parent
cd38cc9fb8
commit
1335750804
4 changed files with 51 additions and 22 deletions
24
dist/habitrpg-shared.js
vendored
24
dist/habitrpg-shared.js
vendored
|
|
@ -63,7 +63,7 @@ process.chdir = function (dir) {
|
|||
};
|
||||
|
||||
},{}],3:[function(require,module,exports){
|
||||
var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {};/**
|
||||
var global=self;/**
|
||||
* @license
|
||||
* Lo-Dash 2.4.1 (Custom Build) <http://lodash.com/>
|
||||
* Build: `lodash modern -o ./dist/lodash.js`
|
||||
|
|
@ -9787,10 +9787,10 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ?
|
|||
text: "Absurd Party Hat",
|
||||
notes: "You've received an Absurd Party Hat! Wear it with pride while ringing in the New Year!",
|
||||
value: 0,
|
||||
canOwn: (function(u) {
|
||||
var _ref;
|
||||
return moment((_ref = u.auth.timestamps) != null ? _ref.created : void 0).isBefore(new Date('01/2/2014'));
|
||||
})
|
||||
canOwn: (function() {
|
||||
return false;
|
||||
}),
|
||||
unbreakable: true
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
@ -10899,6 +10899,12 @@ var process=require("__browserify_process");(function() {
|
|||
});
|
||||
};
|
||||
|
||||
api.countExists = function(items) {
|
||||
return _.reduce(items, (function(m, v) {
|
||||
return m + (v ? 1 : 0);
|
||||
}), 0);
|
||||
};
|
||||
|
||||
/*
|
||||
Even though Mongoose handles task defaults, we want to make sure defaults are set on the client-side before
|
||||
sending up to the server for performance
|
||||
|
|
@ -11223,12 +11229,12 @@ var process=require("__browserify_process");(function() {
|
|||
if (lostStat) {
|
||||
user.stats[lostStat]--;
|
||||
}
|
||||
lostItem = user.fns.randomVal(_.reduce(user.items.gear.owned, (function(m, v, k) {
|
||||
if (v) {
|
||||
m["" + k] = "" + k;
|
||||
lostItem = user.fns.randomVal(_.reduce(user.items.gear.owned, function(m, v, k) {
|
||||
if (v && !content.gear.flat['' + k].unbreakable) {
|
||||
m['' + k] = '' + k;
|
||||
}
|
||||
return m;
|
||||
}), {}));
|
||||
}, {}));
|
||||
if (item = content.gear.flat[lostItem]) {
|
||||
user.items.gear.owned[lostItem] = false;
|
||||
if (user.items.gear.equipped[item.type] === lostItem) {
|
||||
|
|
|
|||
|
|
@ -131,7 +131,7 @@ gear =
|
|||
0: text: "Shade Helm", notes:'Blood and ash, lava and obsidian give this helm its imagery and power. Increases INT by 20.', int: 20, value:150, canOwn: ((u)-> +u.backer?.tier >= 45)
|
||||
1: text: "Crystal Helm", notes:'The favored crown of those who lead by example. Increases all attributes by 6.', con: 6, str: 6, per: 6, int: 6, value:170, canOwn: ((u)-> +u.contributor?.level >= 3)
|
||||
2: text: "Nameless Helm", notes:'A testament to those who gave of themselves while asking nothing in return. Increases INT and STR by 25 each.', int: 25, str: 25, value:200, canOwn: ((u)-> +u.backer?.tier >= 300)
|
||||
nye: text: "Absurd Party Hat", notes:"You've received an Absurd Party Hat! Wear it with pride while ringing in the New Year!", value: 0, canOwn: ((u)-> moment(u.auth.timestamps?.created).isBefore(new Date '01/2/2014'))
|
||||
nye: text: "Absurd Party Hat", notes:"You've received an Absurd Party Hat! Wear it with pride while ringing in the New Year!", value: 0, canOwn: (->false), unbreakable: true
|
||||
#candycane: text: "Candy Cane Hat", notes: 'A hat adorned in candy, a wintery treat!', value:10, canOwn: ((u)-> moment(u.auth.timestamps?.created).isBefore(new Date '01/10/2014'))
|
||||
|
||||
shield:
|
||||
|
|
|
|||
|
|
@ -162,6 +162,8 @@ api.uuid = ->
|
|||
v = (if c is "x" then r else (r & 0x3 | 0x8))
|
||||
v.toString 16
|
||||
|
||||
api.countExists = (items)-> _.reduce(items,((m,v)->m+(if v then 1 else 0)),0)
|
||||
|
||||
###
|
||||
Even though Mongoose handles task defaults, we want to make sure defaults are set on the client-side before
|
||||
sending up to the server for performance
|
||||
|
|
@ -367,8 +369,11 @@ api.wrap = (user) ->
|
|||
|
||||
# Lose a gear piece
|
||||
# Note, they can actually lose item weapon_*_0 - it's 0 to buy back, no big deal
|
||||
# Note the `""+` string-casting. Without this, when run on the server Mongoose returns funny objects
|
||||
lostItem = user.fns.randomVal _.reduce(user.items.gear.owned, ((m,v,k)->m[""+k]=""+k if v;m), {})
|
||||
lostItem = user.fns.randomVal _.reduce user.items.gear.owned, (m,v,k)->
|
||||
# Note ""+k string-casting. Without this, when run on the server Mongoose returns funny objects
|
||||
(m[''+k]=''+k if v and !content.gear.flat[''+k].unbreakable);m
|
||||
, {}
|
||||
|
||||
if item = content.gear.flat[lostItem]
|
||||
user.items.gear.owned[lostItem] = false
|
||||
user.items.gear.equipped[item.type] = "#{item.type}_base_0" if user.items.gear.equipped[item.type] is lostItem
|
||||
|
|
|
|||
|
|
@ -137,15 +137,33 @@ describe 'User', ->
|
|||
user.items.gear.equipped.weapon = 'weapon_wizard_1'
|
||||
expect(user._statsComputed.maxMP).to.eql 63
|
||||
|
||||
it 'revives correctly', ->
|
||||
user = newUser()
|
||||
user.stats = { gp: 10, exp: 100, lvl: 2, hp: 1 }
|
||||
user.ops.revive()
|
||||
expect(user.stats.gp).to.eql 0
|
||||
expect(user.stats.exp).to.eql 0
|
||||
expect(user.stats.lvl).to.eql 1
|
||||
expect(user.stats.hp).to.eql 50
|
||||
expect(user.items.gear.owned).to.eql { weapon_warrior_0: false }
|
||||
describe 'Death', ->
|
||||
it 'revives correctly', ->
|
||||
user = newUser()
|
||||
user.stats = { gp: 10, exp: 100, lvl: 2, hp: 1 }
|
||||
user.ops.revive()
|
||||
expect(user.stats.gp).to.eql 0
|
||||
expect(user.stats.exp).to.eql 0
|
||||
expect(user.stats.lvl).to.eql 1
|
||||
expect(user.stats.hp).to.eql 50
|
||||
expect(user.items.gear.owned).to.eql { weapon_warrior_0: false }
|
||||
|
||||
it "doesn't break unbreakables", ->
|
||||
ce = shared.countExists
|
||||
user = newUser()
|
||||
user.items.gear.owned['shield_rogue_1'] = true
|
||||
user.items.gear.owned['head_special_nye'] = true
|
||||
expect(ce user.items.gear.owned).to.be 3
|
||||
user.ops.revive()
|
||||
console.log(user.items.gear.owned)
|
||||
expect(ce(user.items.gear.owned)).to.be 2
|
||||
user.ops.revive()
|
||||
console.log(user.items.gear.owned)
|
||||
expect(ce(user.items.gear.owned)).to.be 1
|
||||
user.ops.revive()
|
||||
console.log(user.items.gear.owned)
|
||||
expect(ce(user.items.gear.owned)).to.be 1
|
||||
|
||||
|
||||
describe 'store', ->
|
||||
it 'recovers hp buying potions', ->
|
||||
|
|
@ -472,4 +490,4 @@ describe 'Helper', ->
|
|||
|
||||
pets = { "Wolf-Base": 2, "Wolf-Veteran": 1, "Wolf-Cerberus": 1, "Dragon-Hydra": 1}
|
||||
expect(shared.countPets(null, pets)).to.eql 1
|
||||
expect(shared.countPets(_.size(pets), pets)).to.eql 1
|
||||
expect(shared.countPets(_.size(pets), pets)).to.eql 1
|
||||
Loading…
Reference in a new issue