itemShop
This commit is contained in:
parent
efd4e28e2a
commit
a897d9262b
@ -20,6 +20,12 @@ var plugins_comment_c456ea59_6018_45ef_8bcc_211a24c627dc = {
|
|||||||
"_range": "typeof(thiseval)=='string' || thiseval==null",
|
"_range": "typeof(thiseval)=='string' || thiseval==null",
|
||||||
"_data": "绘制灯光效果"
|
"_data": "绘制灯光效果"
|
||||||
},
|
},
|
||||||
|
"drawItemShop": {
|
||||||
|
"_leaf": true,
|
||||||
|
"_type": "textarea",
|
||||||
|
"_range": "typeof(thiseval)=='string' || thiseval==null",
|
||||||
|
"_data": "道具商店插件"
|
||||||
|
},
|
||||||
"smoothCamera": {
|
"smoothCamera": {
|
||||||
"_leaf": true,
|
"_leaf": true,
|
||||||
"_type": "textarea",
|
"_type": "textarea",
|
||||||
|
|||||||
@ -16,10 +16,9 @@
|
|||||||
<link type='text/css' href='styles.css' rel='stylesheet'>
|
<link type='text/css' href='styles.css' rel='stylesheet'>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id='startImageBackgroundDiv'>
|
<div id='startImageBackgroundDiv'>
|
||||||
<div id='startImageDiv'></div>
|
<div id='startImageDiv'></div>
|
||||||
<img id='startImageLogo' />
|
<img id='startImageLogo' />
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<script>
|
<script>
|
||||||
(function () {
|
(function () {
|
||||||
|
|||||||
@ -462,7 +462,7 @@ events.prototype.getItem = function (id, num, x, y, callback) {
|
|||||||
core.removeBlock(x, y);
|
core.removeBlock(x, y);
|
||||||
var text = '获得 ' + core.material.items[id].name;
|
var text = '获得 ' + core.material.items[id].name;
|
||||||
if (num > 1) text += "x" + num;
|
if (num > 1) text += "x" + num;
|
||||||
if (itemCls === 'items') text += core.items.getItemEffectTip(id);
|
if (itemCls === 'items' && num == 1) text += core.items.getItemEffectTip(id);
|
||||||
core.drawTip(text, id);
|
core.drawTip(text, id);
|
||||||
|
|
||||||
// --- 首次获得道具的提示
|
// --- 首次获得道具的提示
|
||||||
@ -2495,7 +2495,11 @@ events.prototype.openShop = function (shopId, needVisited) {
|
|||||||
|
|
||||||
if (shop.item) {
|
if (shop.item) {
|
||||||
core.status.route.push("shop:" + shopId + ":0");
|
core.status.route.push("shop:" + shopId + ":0");
|
||||||
core.insertAction({"type": "insert", "name": "道具商店", "args": [shopId]});
|
if (core.openItemShop) {
|
||||||
|
core.openItemShop(shopId);
|
||||||
|
} else {
|
||||||
|
core.insertAction("道具商店插件不存在!请检查是否存在该插件!");
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
} else if (shop.commonEvent) {
|
} else if (shop.commonEvent) {
|
||||||
core.status.route.push("shop:"+shopId+":0");
|
core.status.route.push("shop:"+shopId+":0");
|
||||||
|
|||||||
@ -59,7 +59,8 @@ items.prototype.getItemEffect = function (itemId, itemNum) {
|
|||||||
var curr_hp = core.status.hero.hp;
|
var curr_hp = core.status.hero.hp;
|
||||||
if (itemId in this.itemEffect) {
|
if (itemId in this.itemEffect) {
|
||||||
try {
|
try {
|
||||||
eval(this.itemEffect[itemId]);
|
for (var i = 0; i < itemNum; ++i)
|
||||||
|
eval(this.itemEffect[itemId]);
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
main.log(e);
|
main.log(e);
|
||||||
|
|||||||
@ -19,17 +19,17 @@ var items_296f5d02_12fd_4166_a7c1_b5e830c9ee3a =
|
|||||||
"redJewel": {
|
"redJewel": {
|
||||||
"cls": "items",
|
"cls": "items",
|
||||||
"name": "红宝石",
|
"name": "红宝石",
|
||||||
"text": "',攻击+'+core.values.redJewel"
|
"text": "',攻击+${core.values.redJewel}'"
|
||||||
},
|
},
|
||||||
"blueJewel": {
|
"blueJewel": {
|
||||||
"cls": "items",
|
"cls": "items",
|
||||||
"name": "蓝宝石",
|
"name": "蓝宝石",
|
||||||
"text": "',防御+'+core.values.blueJewel"
|
"text": "',防御+${core.values.blueJewel}'"
|
||||||
},
|
},
|
||||||
"greenJewel": {
|
"greenJewel": {
|
||||||
"cls": "items",
|
"cls": "items",
|
||||||
"name": "绿宝石",
|
"name": "绿宝石",
|
||||||
"text": "',魔防+'+core.values.greenJewel"
|
"text": "',魔防+${core.values.greenJewel}'"
|
||||||
},
|
},
|
||||||
"yellowJewel": {
|
"yellowJewel": {
|
||||||
"cls": "items",
|
"cls": "items",
|
||||||
|
|||||||
@ -84,6 +84,315 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 =
|
|||||||
ctx.globalCompositeOperation = 'source-over';
|
ctx.globalCompositeOperation = 'source-over';
|
||||||
// 可以在任何地方(如afterXXX或自定义脚本事件)调用函数,方法为 core.plugin.xxx();
|
// 可以在任何地方(如afterXXX或自定义脚本事件)调用函数,方法为 core.plugin.xxx();
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"itemShop": function () {
|
||||||
|
// 道具商店相关的插件
|
||||||
|
|
||||||
|
var shopId = null; // 当前商店ID
|
||||||
|
var type = 0; // 当前正在选中的类型,0买入1卖出
|
||||||
|
var selectItem = 0; // 当前正在选中的道具
|
||||||
|
var selectCount = 0; // 当前已经选中的数量
|
||||||
|
var page = 0;
|
||||||
|
var totalPage = 0;
|
||||||
|
var totalMoney = 0;
|
||||||
|
var list = [];
|
||||||
|
|
||||||
|
var bigFont = core.ui._buildFont(20, false),
|
||||||
|
middleFont = core.ui._buildFont(18, false);
|
||||||
|
|
||||||
|
this.drawItemShop = function () {
|
||||||
|
// 绘制道具商店
|
||||||
|
|
||||||
|
// Step 1: 背景和固定的几个文字
|
||||||
|
core.ui._createUIEvent();
|
||||||
|
this.clearItemShop();
|
||||||
|
core.fillRect('uievent', 0, 0, 416, 416, 'black');
|
||||||
|
core.ui._uievent_drawBackground({ x: 0, y: 0, width: 416, height: 56 });
|
||||||
|
core.ui._uievent_drawBackground({ x: 0, y: 56, width: 312, height: 56 });
|
||||||
|
core.ui._uievent_drawBackground({ x: 0, y: 112, width: 312, height: 304 });
|
||||||
|
core.ui._uievent_drawBackground({ x: 312, y: 56, width: 104, height: 56 });
|
||||||
|
core.ui._uievent_drawBackground({ x: 312, y: 112, width: 104, height: 304 });
|
||||||
|
core.fillText("uievent", "购买", 32, 74, 'white', bigFont);
|
||||||
|
core.fillText("uievent", "卖出", 132, 74);
|
||||||
|
core.fillText("uievent", "离开", 232, 74);
|
||||||
|
core.fillText("uievent", "当前金币", 324, 66, null, middleFont);
|
||||||
|
core.setTextAlign("uievent", "right");
|
||||||
|
core.fillText("uievent", core.formatBigNumber(core.status.hero.money), 405, 89);
|
||||||
|
core.setTextAlign("uievent", "left");
|
||||||
|
core.ui._uievent_drawSelector({
|
||||||
|
"type": "drawSelector",
|
||||||
|
"image": "winskin.png",
|
||||||
|
"code": 2,
|
||||||
|
"x": 22 + 100 * type,
|
||||||
|
"y": 66,
|
||||||
|
"width": 60,
|
||||||
|
"height": 33
|
||||||
|
});
|
||||||
|
if (selectItem != null) {
|
||||||
|
core.setTextAlign('uievent', 'center');
|
||||||
|
core.fillText("uievent", type == 0 ? "买入个数" : "卖出个数", 364, 320, null, bigFont);
|
||||||
|
core.fillText("uievent", "◀ " + selectCount + " ▶", 364, 350);
|
||||||
|
core.fillText("uievent", "确定", 364, 380);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Step 2:获得列表并展示
|
||||||
|
var choices = core.status.shops[shopId].choices;
|
||||||
|
list = choices.filter(function (one) {
|
||||||
|
return (type == 0 && one.money != null) || (type == 1 && one.sell != null);
|
||||||
|
});
|
||||||
|
var per_page = 6;
|
||||||
|
totalPage = Math.ceil(list.length / per_page);
|
||||||
|
page = Math.floor((selectItem || 0) / per_page) + 1;
|
||||||
|
|
||||||
|
// 绘制分页
|
||||||
|
if (totalPage > 1) {
|
||||||
|
var half = 156;
|
||||||
|
core.setTextAlign('uievent', 'center');
|
||||||
|
core.fillText('uievent', page + " / " + totalPage, half, 388, null, middleFont);
|
||||||
|
if (page > 1) core.fillText('uievent', '上一页', half - 80, 388);
|
||||||
|
if (page < totalPage) core.fillText('uievent', '下一页', half + 80, 388);
|
||||||
|
}
|
||||||
|
core.setTextAlign('uievent', 'left');
|
||||||
|
|
||||||
|
// 绘制每一项
|
||||||
|
var start = (page - 1) * per_page;
|
||||||
|
for (var i = 0; i < per_page; ++i) {
|
||||||
|
var curr = start + i;
|
||||||
|
if (curr >= list.length) break;
|
||||||
|
var item = list[curr];
|
||||||
|
core.drawIcon('uievent', item.id, 10, 125 + i * 40);
|
||||||
|
core.setTextAlign('uievent', 'left');
|
||||||
|
core.fillText('uievent', core.material.items[item.id].name, 50, 132 + i * 40, null, bigFont);
|
||||||
|
core.setTextAlign('uievent', 'right');
|
||||||
|
core.fillText('uievent', (type == 0 ? item.money : item.sell) + "金币/个", 300, 133 + i * 40, null, middleFont);
|
||||||
|
core.setTextAlign("uievent", "left");
|
||||||
|
if (curr == selectItem) {
|
||||||
|
// 绘制描述,文字自动放缩
|
||||||
|
var text = core.material.items[item.id].text || "该道具暂无描述";
|
||||||
|
try { text = core.replaceText(text); } catch (e) {}
|
||||||
|
for (var fontSize = 20; fontSize >= 8; fontSize -= 2) {
|
||||||
|
var config = { left: 10, fontSize: fontSize, maxWidth: 403, lineHeight: 1.4 };
|
||||||
|
var height = core.getTextContentHeight(text, config);
|
||||||
|
if (height <= 50) {
|
||||||
|
config.top = (56 - height) / 2;
|
||||||
|
core.drawTextContent("uievent", text, config);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
core.ui._uievent_drawSelector({ "type": "drawSelector", "image": "winskin.png", "code": 1, "x": 8, "y": 120 + i * 40, "width": 295, "height": 40 });
|
||||||
|
if (type == 0 && item.number != null) {
|
||||||
|
core.fillText("uievent", "存货", 324, 132, null, bigFont);
|
||||||
|
core.setTextAlign("uievent", "right");
|
||||||
|
core.fillText("uievent", item.number, 406, 132, null, null, 40);
|
||||||
|
} else if (type == 1) {
|
||||||
|
core.fillText("uievent", "数量", 324, 132, null, bigFont);
|
||||||
|
core.setTextAlign("uievent", "right");
|
||||||
|
core.fillText("uievent", core.itemCount(item.id), 406, 132, null, null, 40);
|
||||||
|
}
|
||||||
|
core.setTextAlign("uievent", "left");
|
||||||
|
core.fillText("uievent", "合计金额", 324, 190);
|
||||||
|
core.setTextAlign("uievent", "right");
|
||||||
|
totalMoney = selectCount * (type == 0 ? item.money : item.sell);
|
||||||
|
core.fillText("uievent", core.formatBigNumber(totalMoney), 405, 220);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
core.setTextAlign('uievent', 'left');
|
||||||
|
core.setTextBaseline('uievent', 'alphabetic');
|
||||||
|
}
|
||||||
|
|
||||||
|
this.clearItemShop = function () {
|
||||||
|
core.clearMap('uievent');
|
||||||
|
core.ui._uievent_drawSelector({ "code": 1 });
|
||||||
|
core.ui._uievent_drawSelector({ "code": 2 });
|
||||||
|
core.setTextAlign('uievent', 'left');
|
||||||
|
core.setTextBaseline('uievent', 'top');
|
||||||
|
core.setFillStyle('uievent', 'white');
|
||||||
|
core.setStrokeStyle('uievent', 'white');
|
||||||
|
}
|
||||||
|
|
||||||
|
var _add = function (item, delta) {
|
||||||
|
if (item == null) return;
|
||||||
|
selectCount = core.clamp(
|
||||||
|
selectCount + delta, 0,
|
||||||
|
Math.min(type == 0 ? Math.floor(core.status.hero.money / item.money) : core.itemCount(item.id),
|
||||||
|
type == 0 && item.number != null ? item.number : Number.MAX_SAFE_INTEGER)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
var _confirm = function (item) {
|
||||||
|
if (item == null || selectCount == 0) return;
|
||||||
|
if (type == 0) {
|
||||||
|
core.status.hero.money -= totalMoney;
|
||||||
|
core.getItem(item.id, selectCount);
|
||||||
|
if (item.number != null) item.number -= selectCount;
|
||||||
|
} else {
|
||||||
|
core.status.hero.money += totalMoney;
|
||||||
|
core.removeItem(item.id, selectCount);
|
||||||
|
core.drawTip("成功卖出" + selectCount + "个" + core.material.items[item.id].name, item.id);
|
||||||
|
if (item.number != null) item.number += selectCount;
|
||||||
|
}
|
||||||
|
selectCount = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
this._performItemShopKeyBoard = function (keycode) {
|
||||||
|
var item = list[selectItem] || null;
|
||||||
|
// 键盘操作
|
||||||
|
switch (keycode) {
|
||||||
|
case 38: // up
|
||||||
|
if (selectItem == null) break;
|
||||||
|
if (selectItem == 0) selectItem = null;
|
||||||
|
else selectItem--;
|
||||||
|
selectCount = 0;
|
||||||
|
break;
|
||||||
|
case 37: // left
|
||||||
|
if (selectItem == null) {
|
||||||
|
if (type > 0) type--;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
_add(item, -1);
|
||||||
|
break;
|
||||||
|
case 39: // right
|
||||||
|
if (selectItem == null) {
|
||||||
|
if (type < 2) type++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
_add(item, 1);
|
||||||
|
break;
|
||||||
|
case 40: // down
|
||||||
|
if (selectItem == null) {
|
||||||
|
if (list.length > 0) selectItem = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (list.length == 0) break;
|
||||||
|
selectItem = Math.min(selectItem + 1, list.length - 1);
|
||||||
|
selectCount = 0;
|
||||||
|
break;
|
||||||
|
case 13:
|
||||||
|
case 32: // SpaceBar/Space
|
||||||
|
if (selectItem == null) {
|
||||||
|
if (type == 2)
|
||||||
|
core.insertAction({ "type": "break" });
|
||||||
|
else if (list.length > 0)
|
||||||
|
selectItem = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
_confirm(item);
|
||||||
|
break;
|
||||||
|
case 27: // ESC
|
||||||
|
if (selectItem == null) {
|
||||||
|
core.insertAction({ "type": "break" });
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
selectItem = null;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this._performItemShopClick = function (px, py) {
|
||||||
|
var item = list[selectItem] || null;
|
||||||
|
// 鼠标操作
|
||||||
|
console.log(px, py);
|
||||||
|
if (px >= 22 && px <= 82 && py >= 71 && py <= 102) {
|
||||||
|
// 买
|
||||||
|
if (type != 0) {
|
||||||
|
type = 0;
|
||||||
|
selectItem = null;
|
||||||
|
selectCount = 0;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (px >= 122 && px <= 182 && py >= 71 && py <= 102) {
|
||||||
|
// 卖
|
||||||
|
if (type != 1) {
|
||||||
|
type = 1;
|
||||||
|
selectItem = null;
|
||||||
|
selectCount = 0;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (px >= 222 && px <= 282 && py >= 71 && py <= 102) // 离开
|
||||||
|
return core.insertAction({ "type": "break" });
|
||||||
|
// ◀,▶
|
||||||
|
if (px >= 318 && px <= 341 && py >= 348 && py <= 376)
|
||||||
|
return _add(item, -1);
|
||||||
|
if (px >= 388 && px <= 416 && py >= 348 && py <= 376)
|
||||||
|
return _add(item, 1);
|
||||||
|
// 确定
|
||||||
|
if (px >= 341 && px <= 387 && py >= 380 && py <= 407)
|
||||||
|
return _confirm(item);
|
||||||
|
|
||||||
|
// 上一页/下一页
|
||||||
|
if (px >= 45 && px <= 105 && py >= 388) {
|
||||||
|
if (page > 1) selectItem -= 6;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (px >= 208 && px <= 268 && py >= 388) {
|
||||||
|
if (page < totalPage) selectItem = Math.min(selectItem + 6, list.length - 1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 实际区域
|
||||||
|
if (px >= 9 && px <= 300 && py >= 120 && py < 360) {
|
||||||
|
var index = parseInt((py - 120) / 40);
|
||||||
|
var newItem = 6 * (page - 1) + index;
|
||||||
|
if (newItem >= list.length) newItem = list.length - 1;
|
||||||
|
if (newItem != selectItem) {
|
||||||
|
selectItem = newItem;
|
||||||
|
selectCount = 0;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.performItemShopAction = function () {
|
||||||
|
if (flags.type == 0) return this._performItemShopKeyBoard(flags.keycode);
|
||||||
|
else return this._performItemShopClick(flags.px, flags.py);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.openItemShop = function (itemShopId) {
|
||||||
|
shopId = itemShopId;
|
||||||
|
type = 0;
|
||||||
|
page = 0;
|
||||||
|
selectItem = null;
|
||||||
|
selectCount = 0;
|
||||||
|
core.insertAction([{
|
||||||
|
"type": "while",
|
||||||
|
"condition": "true",
|
||||||
|
"data": [
|
||||||
|
{ "type": "function", "function": "function () { core.drawItemShop(); }" },
|
||||||
|
{ "type": "wait" },
|
||||||
|
{ "type": "function", "function": "function() { core.performItemShopAction(); }" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{ "type": "function", "function": "function () { core.clearItemShop(); core.deleteCanvas('uievent'); }" }
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write item number to save
|
||||||
|
core.control.saveData = function () {
|
||||||
|
var data = this.controldata.saveData();
|
||||||
|
for (var shopId in core.status.shops) {
|
||||||
|
if (core.status.shops[shopId].item) {
|
||||||
|
data.shops[shopId].number = core.status.shops[shopId].choices.map(function (t) {
|
||||||
|
return t.number == null ? null : t.number;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
core.control.loadData = function (data, callback) {
|
||||||
|
this.controldata.loadData(data, callback);
|
||||||
|
for (var shopId in data.shops) {
|
||||||
|
if (data.shops[shopId].number) {
|
||||||
|
for (var i = 0; i < data.shops[shopId].number.length; ++i) {
|
||||||
|
core.status.shops[shopId].choices[i].number = data.shops[shopId].number[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
"smoothCamera": function () {
|
"smoothCamera": function () {
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user