Skip to content

Commit

Permalink
- add dropchance in site stats
Browse files Browse the repository at this point in the history
- change droptime date from telegram message  time to server local time
  • Loading branch information
Lor-Saba committed Jan 5, 2022
1 parent cf6da4c commit b743334
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 5 deletions.
14 changes: 12 additions & 2 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ function startSite(){
var chatId = cryptr.decrypt(params.chatId);
var userId = cryptr.decrypt(params.userId);
var user = storage.getUser(userId);
var chat = storage.getChat(chatId);
var userStats = user.chats[chatId];
var lexicon = Lexicon.lang('en');
var ctx = { state: { lexicon: lexicon, mexData: { chatId: chatId } } };
Expand Down Expand Up @@ -166,6 +167,15 @@ function startSite(){
data.challengesLost = userStats.challengeLostTotal;
data.challengesRateo = (Number(userStats.challengeWonTotal) / (Number(userStats.challengeLostTotal) || 1)).toFixed(2);
}

// aggiunge la chance di drop
var chatItemsBuff = items.getItemsBuff(chat.items);
var dropCooldownTime = (60 * 60 * 8) * chatItemsBuff.drop_cd;
data.drop = {
cooldownTime: userStats.lastItemDate + dropCooldownTime - (Date.now() / 1000),
cooldownActive: userStats.lastItemDate + dropCooldownTime >= (Date.now() / 1000),
chance: ((0.015 + userStats.itemsDropGrow) * chatItemsBuff.drop_chance).toFixed(4)
};

// aggiunge il livello massimo raggiunto
if (BigNumber(userStats.levelReached).isGreaterThan(0)) {
Expand Down Expand Up @@ -2371,15 +2381,15 @@ function dropItemChance(ctx, user){
// chance di drop
var dropchance = (0.015 + userStats.itemsDropGrow) * chatItemsBuff.drop_chance;
// determina se è in cooldown
var notCoolingDown = userStats.lastItemDate + cooldownTime < mexData.date;
var notCoolingDown = userStats.lastItemDate + cooldownTime < (Date.now() / 1000);
// determina se puo' droppare
var canDrop = Math.random() < dropchance;

// probabilità di ottenere un oggetto
if (notCoolingDown && canDrop) {

userStats.itemsDropGrow = 0;
userStats.lastItemDate = mexData.date;
userStats.lastItemDate = (Date.now() / 1000);

var dropText = '';
var item = items.pickDrop();
Expand Down
3 changes: 3 additions & 0 deletions modules/lexicon/keys/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ module.exports = {
"STATS_EPM_LABEL": {
"en": "Exp per message"
},
"STATS_DC_LABEL": {
"en": "Drop chance"
},
"STATS_PRESTIGE_BONUS": {
"en": "Prestige bonus: `+$(value)%`"
},
Expand Down
2 changes: 1 addition & 1 deletion modules/site/public/script/mystats.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function changePage(el){
}

Zepto(function(){
setLiveTimeoutDate('.item-timeoutduration');
setLiveTimeoutDate('.item-timeoutduration , .field-timeoutduration');

$('.loader-toggler').on('click', function(){
toggleLoader(true);
Expand Down
14 changes: 14 additions & 0 deletions modules/site/public/style/chatstats.css
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,20 @@ body {
box-shadow: 0 0 0 7px rgba(153,34,234,0);
}
}
.field-timeouticon .icon {
width: 15px;
height: 15px;
vertical-align: sub;
margin: 0 2px 0 0;
color: #b34b4b;
}
.field-timeoutduration {
display: inline-flex;
color: #b34b4b;
font-size: 13px;
font-family: Oxanium;
margin-top: 2px;
}
.empty {
text-align: center;
}
Expand Down
14 changes: 14 additions & 0 deletions modules/site/public/style/mystats.css
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,20 @@ body {
box-shadow: 0 0 0 7px rgba(153,34,234,0);
}
}
.field-timeouticon .icon {
width: 15px;
height: 15px;
vertical-align: sub;
margin: 0 2px 0 0;
color: #b34b4b;
}
.field-timeoutduration {
display: inline-flex;
color: #b34b4b;
font-size: 13px;
font-family: Oxanium;
margin-top: 2px;
}
.empty {
text-align: center;
}
Expand Down
2 changes: 1 addition & 1 deletion modules/site/src/script/mystats.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//=require common/tabs.js

Zepto(function(){
setLiveTimeoutDate('.item-timeoutduration');
setLiveTimeoutDate('.item-timeoutduration , .field-timeoutduration');

$('.loader-toggler').on('click', function(){
toggleLoader(true);
Expand Down
17 changes: 17 additions & 0 deletions modules/site/src/style/common/fields.styl
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,23 @@
}
}

.field-timeouticon {
.icon {
width: 15px;
height: 15px;
vertical-align: sub;
margin: 0 2px 0 0;
color: #b34b4b;
}
}
.field-timeoutduration {
display: inline-flex;
color: #b34b4b;
font-size: 13px;
font-family: Oxanium;
margin-top: 2px;
}

.empty {
text-align: center;

Expand Down
14 changes: 13 additions & 1 deletion modules/site/views/mystats.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,22 @@

<div class="field-separator"></div>

<div class="field">
<div class="field half">
<div class="field-title">{{lexicon 'STATS_EPM_LABEL'}}</div>
<div class="field-value">{{ stats.expPerMessage }}</div>
</div>
<div class="field half">
<div class="field-title">{{lexicon 'STATS_DC_LABEL'}}</div>
<div class="field-value">

{{#if stats.drop.cooldownActive}}
<span class="field-timeouticon">{{> svg-icon name="clock"}}</span>
<span class="field-timeoutduration" data-timeout="{{ stats.drop.cooldownTime }}"></span>
{{else}}
{{ stats.drop.chance }} %
{{/if}}
</div>
</div>
{{#if stats.hasChallenges}}
<div class="field half">
<div class="field-title">{{lexicon 'STATS_CHALLENGE_TOTAL_LABEL'}}</div>
Expand Down

0 comments on commit b743334

Please sign in to comment.