Pārlūkot izejas kodu

Merge branch '282-send-mail' into 'v0.1.6.1'

Resolve "Award 2 marks to everyone that participates in the fishing tournament"

See merge request !209
tags/v0.1.7^2
Big Bad Waffle pirms 6 gadiem
vecāks
revīzija
bd13d8a893
16 mainītis faili ar 409 papildinājumiem un 15 dzēšanām
  1. +1
    -1
      src/client/css/main.less
  2. +2
    -2
      src/client/ui/factory.js
  3. +13
    -0
      src/client/ui/templates/inventory/inventory.js
  4. +102
    -0
      src/client/ui/templates/mail/mail.js
  5. +113
    -0
      src/client/ui/templates/mail/styles.less
  6. +17
    -0
      src/client/ui/templates/mail/template.html
  7. +29
    -0
      src/server/components/inventory.js
  8. +2
    -0
      src/server/components/stats.js
  9. +10
    -0
      src/server/misc/mail.js
  10. +2
    -4
      src/server/security/connections.js
  11. +1
    -1
      src/server/security/router.js
  12. +18
    -3
      src/server/world/atlas.js
  13. +2
    -0
      src/server/world/instancer.js
  14. +23
    -4
      src/server/world/worker.js
  15. +18
    -0
      tests/package-lock.json
  16. +56
    -0
      tests/server/components/dialogue.js

+ 1
- 1
src/client/css/main.less Parādīt failu

@@ -73,4 +73,4 @@ body {
-webkit-border-radius: 10px;
border-radius: 0px;
background: @lightGray;
}
}

+ 2
- 2
src/client/ui/factory.js Parādīt failu

@@ -33,7 +33,6 @@ define([
'help',
'dialogue',
'buffs',
'partyLoot',
'tooltips',
'tooltipInfo',
'tooltipItem',
@@ -48,7 +47,8 @@ define([
'overlay',
'death',
'leaderboard',
'reputation'
'reputation',
'mail'
].forEach(function(u) {
this.build(u);
}, this);


+ 13
- 0
src/client/ui/templates/inventory/inventory.js Parādīt failu

@@ -281,6 +281,10 @@ define([
text: 'augment',
callback: this.openAugmentUi.bind(this, item)
},
mail: {
text: 'mail',
callback: this.openMailUi.bind(this, item)
},
divider: '----------'
};

@@ -320,6 +324,9 @@ define([
config.push(menuItems.destroy);
}

if ((!item.noDrop) && (!item.quest) && (!item.noSalvage))
config.push(menuItems.mail);

if (config.length > 0)
events.emit('onContextMenu', config, e);

@@ -459,6 +466,12 @@ define([
});
},

openMailUi: function(item) {
events.emit('onSetMailItem', {
item: item
});
},

onKeyDown: function(key) {
if (key == 'i')
this.toggle();


+ 102
- 0
src/client/ui/templates/mail/mail.js Parādīt failu

@@ -0,0 +1,102 @@
define([
'js/system/events',
'js/system/client',
'html!ui/templates/mail/template',
'css!ui/templates/mail/styles'
], function(
events,
client,
template,
styles
) {
return {
tpl: template,

centered: true,

modal: true,

item: null,

postRender: function() {
this.onEvent('onSetMailItem', this.onSetItem.bind(this));

this.find('.btnSend').on('click', this.onSendClick.bind(this));
},

onSendClick: function() {
if (!this.item)
return;

var recipient = this.find('.txtRecipient').val();
if (recipient.length == 0)
return;

client.request({
cpn: 'player',
method: 'performAction',
data: {
cpn: 'inventory',
method: 'mailItem',
data: {
itemId: this.item.id,
recipient: recipient
}
},
callback: this.onSend.bind(this)
});
},
onSend: function(res) {
if (res.length > 0) {
events.emit('onGetAnnouncement', {
msg: res,
type: 'failure'
});

return;
}

this.hide();
},

onSetItem: function(msg) {
this.toggle();
this.item = msg.item;

var item = msg.item;

var imgX = -item.sprite[0] * 64;
var imgY = -item.sprite[1] * 64;

var spritesheet = item.spritesheet || '../../../images/items.png';
if (item.material)
spritesheet = '../../../images/materials.png';
else if (item.quest)
spritesheet = '../../../images/questItems.png';

var el = this.find('.item');

el
.data('item', item)
/*.on('mousemove', this.onHover.bind(this, el, item))
.on('mouseleave', this.hideTooltip.bind(this, el, item))*/
.find('.icon')
.css('background', 'url(' + spritesheet + ') ' + imgX + 'px ' + imgY + 'px');


if (item.quantity) {
var quantityText = item.quantity;
el.find('.quantity').html(item.quantity);
}
},

toggle: function() {
this.shown = !this.el.is(':visible');

if (this.shown) {
this.show();
} else
this.hide();
}
}
});

+ 113
- 0
src/client/ui/templates/mail/styles.less Parādīt failu

@@ -0,0 +1,113 @@
@import "../../../css/ui.less";

.uiMail {
display: none;

background-color: @blackB;
border: 5px solid #c0c3cf;
padding: 10px;

.top {
margin-bottom: 10px;

.heading {
color: @orange;
text-align: center;
}
}

.bottom {
.col {
float: left;
width: 80px;
height: 80px;

&:nth-child(2) {
width: 200px;
padding-top: 4px;

> * {
width: 100%;
height: 31px;
}

.btnSend {
height: 35px;
background-color: @blueB;
text-align: center;
padding-top: 12px;
color: @white;
}

input, input:-webkit-autofill {
box-shadow: 0 0 0px 1000px darken(@blackB, 15%) inset;
color: @white;
-webkit-text-fill-color: @white;
margin-bottom: 5px;
text-align: center;
}

/* We duplicate this for firefox which doesn't like the webkit selector */
input {
box-shadow: 0 0 0px 1000px darken(@blackB, 15%) inset;
color: @white;
-webkit-text-fill-color: @white;
margin-bottom: 5px;
text-align: center;
}
}

.item {
width: 100%;
height: 100%;
float: left;
position: relative;
cursor: pointer;
box-sizing: border-box;

.quantity {
left: 6px;
bottom: 3px;
position: absolute;
color: @white;
filter:
drop-shadow(0px -2px 0px @blackD)
drop-shadow(0px 2px 0px @blackD)
drop-shadow(2px 0px 0px @blackD)
drop-shadow(-2px 0px 0px @blackD);

-moz-filter:
drop-shadow(0px -2px 0px @blackD)
drop-shadow(0px 2px 0px @blackD)
drop-shadow(2px 0px 0px @blackD)
drop-shadow(-2px 0px 0px @blackD);

&.red {
color: @red;
}
}

.icon {
width: 64px;
height: 64px;
position: absolute;
left: 8px;
top: 8px;
filter:
brightness(100%)
drop-shadow(0px -4px 0px @blackD)
drop-shadow(0px 4px 0px @blackD)
drop-shadow(4px 0px 0px @blackD)
drop-shadow(-4px 0px 0px @blackD);

-moz-filter:
brightness(100%)
drop-shadow(0px -4px 0px @blackD)
drop-shadow(0px 4px 0px @blackD)
drop-shadow(4px 0px 0px @blackD)
drop-shadow(-4px 0px 0px @blackD);
}
}
}
}
}

+ 17
- 0
src/client/ui/templates/mail/template.html Parādīt failu

@@ -0,0 +1,17 @@
<div class="uiMail">
<div class="top">
<div class="heading">mail item</div>
</div>
<div class="bottom">
<div class="col">
<div class="item">
<div class="icon"></div>
<div class="quantity"></div>
</div>
</div>
<div class="col">
<input class="txtRecipient textbox" type="text" placeholder="recipient">
<div class="btnSend">send</div>
</div>
</div>
</div>

+ 29
- 0
src/server/components/inventory.js Parādīt failu

@@ -296,6 +296,35 @@ define([
}, this);
},

mailItem: function(msg) {
var item = this.findItem(msg.itemId);
if (!item) {
this.resolveCallback(msg);
return;
}

delete item.pos;

var io = require('security/io');
io.get({
ent: msg.recipient,
field: 'character',
callback: this.onCheckCharExists.bind(this, msg, item)
});
},
onCheckCharExists: function(msg, item, res) {
if (!res) {
this.resolveCallback(msg, 'Recipient does not exist');
return;
}

this.obj.instance.mail.sendMail(msg.recipient, [ extend(true, {}, item) ]);

this.destroyItem(item.id);

this.resolveCallback(msg);
},

//Helpers

resolveCallback: function(msg, result) {


+ 2
- 0
src/server/components/stats.js Parādīt failu

@@ -548,6 +548,8 @@ define([
var rewards = loginRewards.generate(stats.loginStreak);
mail.sendMail(this.obj.name, rewards);
}
else
this.obj.instance.mail.getMail(this.obj.name);

stats.lastLogin = time;
}


+ 10
- 0
src/server/misc/mail.js Parādīt failu

@@ -14,6 +14,16 @@ define([
getMail: function(playerName) {
var player = this.instance.objects.objects.find(o => (o.name == playerName));
if (!player) {
process.send({
method: 'callDifferentThread',
playerName: playerName,
data: {
module: 'mail',
method: 'getMail',
args: [ playerName ]
}
});

this.processQueue(playerName);
return;
}


+ 2
- 4
src/server/security/connections.js Parādīt failu

@@ -1,9 +1,7 @@
define([
'objects/objects',
'world/atlas'
'objects/objects'
], function(
objects,
atlas
objects
) {
return {
players: [],


+ 1
- 1
src/server/security/router.js Parādīt failu

@@ -22,7 +22,7 @@ define([
dialogue: ['talk'],
gatherer: ['gather'],
quests: ['complete'],
inventory: ['moveItem', 'enchantItem', 'getEnchantMaterials', 'learnAbility', 'unlearnAbility', 'dropItem', 'destroyItem', 'salvageItem', 'stashItem', ''],
inventory: ['moveItem', 'enchantItem', 'getEnchantMaterials', 'learnAbility', 'unlearnAbility', 'dropItem', 'destroyItem', 'salvageItem', 'stashItem', 'mailItem'],
equipment: ['equip', 'unequip'],
stash: ['withdraw'],
trade: ['buySell' ],


+ 18
- 3
src/server/world/atlas.js Parādīt failu

@@ -2,12 +2,14 @@ define([
'../misc/fileLister',
'child_process',
'objects/objects',
'config/maps/mapList'
'config/maps/mapList',
'security/connections'
], function(
fileLister,
childProcess,
objects,
mapList
mapList,
connections
) {
return {
nextId: 0,
@@ -103,7 +105,6 @@ define([
if (!callback)
return;


callback.callback(msg.result);
},

@@ -160,6 +161,20 @@ define([
object: function(thread, message) {
objects.updateObject(message);
},
callDifferentThread: function(thread, message) {
var obj = connections.players.find(p => (p.name == message.playerName));
if (!obj)
return;
var thread = this.getThreadFromName(obj.zoneName);
if (!thread)
return;

thread.worker.send({
module: message.data.module,
method: message.data.method,
args: message.data.args
});
},
rezone: function(thread, message) {
var obj = message.args.obj;
obj.destroyed = false;


+ 2
- 0
src/server/world/instancer.js Parādīt failu

@@ -56,6 +56,8 @@ define([
scheduler: scheduler
};

this.instances.push(fakeInstance);

spawners.init(fakeInstance);
scheduler.init();



+ 23
- 4
src/server/world/worker.js Parādīt failu

@@ -8,8 +8,6 @@ requirejs.config({
global.io = true;
var instancer = null;



requirejs([
'extend', 'misc/helpers', 'components/components', 'world/instancer', 'security/io', 'misc/mods'
], function(
@@ -18,6 +16,7 @@ requirejs([
var onDbReady = function() {
global.extend = extend;
global._ = helpers;
global.instancer = _instancer;
require('../misc/random');
instancer = _instancer;
@@ -39,7 +38,27 @@ requirejs([
});

process.on('message', (m) => {
if (m.method) {
if (m.module) {
var instances = instancer.instances;
var iLen = instances.length;
for (var i = 0; i < iLen; i++) {
var objects = instances[i].objects.objects;
var oLen = objects.length;
var found = false;
for (var j = 0; j < oLen; j++) {
var object = objects[j];

if (object.name == m.args[0]) {
var module = object.instance[m.module];
module[m.method].apply(module, m.args);

found = true;
break;
}
}
if (found)
break;
}
} else if (m.method)
instancer[m.method](m.args);
}
});

+ 18
- 0
tests/package-lock.json Parādīt failu

@@ -0,0 +1,18 @@
{
"name": "isleward-tests",
"version": "0.0.1",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"extend": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/extend/-/extend-3.0.1.tgz",
"integrity": "sha1-p1Xqe8Gt/MWjHOfnYtuq3F5jZEQ="
},
"requirejs": {
"version": "2.3.5",
"resolved": "https://registry.npmjs.org/requirejs/-/requirejs-2.3.5.tgz",
"integrity": "sha512-svnO+aNcR/an9Dpi44C7KSAy5fFGLtmPbaaCeQaklUz8BQhS64tWWIIlvEA5jrWICzlO/X9KSzSeXFnZdBu8nw=="
}
}
}

+ 56
- 0
tests/server/components/dialogue.js Parādīt failu

@@ -0,0 +1,56 @@
define([
'server/mocks/generator'
], function(
mocks
) {
return {
//Do you get the correct reputation when talking to a faction vendor for the first time
startTalk_DiscoverFaction: function() {
var factionBase = require('../src/server/config/factionBase');
var anglers = require('../src/server/config/factions/anglers');
var factionBlueprint = extend(true, {}, factionBase, anglers);

var player = mocks.player({
dialogue: {

},
reputation: {
getBlueprint: function() {
return factionBlueprint;
}
}
});

var resultMsg = null;
player.instance.syncer.queue = function(event, msg) {
resultMsg = msg.messages[0].message;
};

var target = mocks.player({
dialogue: {

},
trade: {
faction: {
id: 'anglers'
}
}
});

player.dialogue.talk({
target: target
});

var rep = player.reputation.list[0];
if (rep.rep != factionBlueprint.initialRep)
return true;
else if (resultMsg.indexOf(' friendly ') == -1)
return true;
else {
var tierName = factionBlueprint.tiers.find(t => (t.rep == rep.rep)).name.toLowerCase();
if (resultMsg.indexOf(` ${tierName} `) == -1)
return true;
}
}
};
});

Notiek ielāde…
Atcelt
Saglabāt