Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Destat NPC #119

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions design/maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -1221,6 +1221,7 @@
"npcs":[
{"id":"transporter","position":[-14,-477]},
{"id":"locksmith","position":[316,-270]},
{"id":"scrollsmith","position":[606,-1590]},
],
"monsters":[
{"type":"plantoid","boundary":[-1013,-472,-575,-130],"count":4,"grow":True}, #added grow 31/1/2024
Expand Down
7 changes: 7 additions & 0 deletions design/npcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,13 @@
"type":"fullstatic",
"name":"Smith",
},
"scrollsmith":{
"role":"scrollsmith",
"skin":"bsoldier",
"says":"X",
"type":"fullstatic",
"name":"Sir Bob",
},
"transporter":{
"role":"transport",
"skin":"spell",
Expand Down
4 changes: 2 additions & 2 deletions design/sprites.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@
"columns":4,
"matrix":[
[None,"nexus",None,None],
[None,None,None,None],
[None,None,"bsoldier",None],
]
},
"military3":{
Expand Down Expand Up @@ -1136,4 +1136,4 @@
"ruins":{"file":"/images/tiles/map/ruins.png?v=2"},
"tree":{"file":"/images/tiles/map/tree.png"},
"lights":{"file":"/images/tiles/map/lights.png?v=3","light":"yes"}, # "frames":3,"frame_width":48,
}
}
11 changes: 10 additions & 1 deletion js/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2953,6 +2953,14 @@ function lock_item(num)
return push_deferred("locksmith");
}

function destat_item(num)
{
if(num===undefined) num=s_item;
socket.emit("destat",{num:num});
return push_deferred("destat");
}


function seal_item(num)
{
if(num===undefined) num=l_item;
Expand Down Expand Up @@ -3204,6 +3212,7 @@ function reopen()
else if(rendered_target=="dismantler") render_dismantler();
else if(rendered_target=="none") render_none_shrine();
else if(rendered_target=="locksmith") render_locksmith();
else if(rendered_target=="scrollsmith") render_scrollsmith();
// else if(rendered_target=="secondhands") render_secondhands(); // Manual resets
if(inventory) reset_inventory();

Expand Down Expand Up @@ -3270,7 +3279,7 @@ function reset_inventory(condition)
{
if(inventory)
{
if(condition && !in_arr(rendered_target,["upgrade","compound","exchange","npc","merchant","craftsman","dismantler","none","locksmith"])) return;
if(condition && !in_arr(rendered_target,["upgrade","compound","exchange","npc","merchant","craftsman","dismantler","none","locksmith","scrollsmith"])) return;
render_inventory(true);
}
}
Expand Down
13 changes: 13 additions & 0 deletions js/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -2194,6 +2194,15 @@ function init_socket(args)
}
else if(response=="magiport_failed") ui_log("Magiport failed","gray"),no_no_no(2);
else if(response=="revive_failed") ui_log("Revival failed","gray"),no_no_no(1);
else if(response=="scrollsmith_cant")
{
ui_log("Can't destat this item","gray")
}
else if(response=="scrollsmith_success")
{
ui_log("Spent " + data.gold.toLocaleString() + " gold","gray");
ui_log("De-statted the item","gray");
}
else if(response=="locksmith_cant")
{
ui_log("Can't lock/unlock this item","gray")
Expand Down Expand Up @@ -3257,6 +3266,10 @@ function npc_right_click(event){
{
render_interaction({auto:true,dialog:"locksmith",skin:"asoldier"});
}
if(this.role=="scrollsmith")
{
render_interaction({auto:true,dialog:"scrollsmith",skin:"bsoldier"});
}
if(this.role=="compound")
{
render_compound_shrine(1);
Expand Down
42 changes: 41 additions & 1 deletion js/html.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var u_item=null,u_scroll=null,u_offering=null,c_items=e_array(3),c_scroll=null,c_offering=null,c_last=0,e_item=null,p_item=null,l_item=null,cr_items=e_array(9),cr_last=0,ds_item=null;
var u_item=null,u_scroll=null,u_offering=null,c_items=e_array(3),c_scroll=null,c_offering=null,c_last=0,e_item=null,p_item=null,l_item=null,s_item=null,cr_items=e_array(9),cr_last=0,ds_item=null;

var settings_shown=0;
function show_settings()
Expand Down Expand Up @@ -1142,6 +1142,30 @@ function render_locksmith(mode)
if(!inventory) render_inventory(),inventory_opened_for=topleft_npc;
}

function render_scrollsmith()
{
var button="DE-STAT",f="destat_item",shade="shade_chest";
reset_inventory(1);
topleft_npc="scrollsmith"; rendered_target=topleft_npc;
s_item=null;
var html="<div style='background-color: black; border: 5px solid gray; padding: 20px; font-size: 24px; display: inline-block; vertical-align: top; text-align: center'>";
/*html+="<div class='ering ering1 mb10'>";
html+="<div class='ering ering2'>";
html+="<div class='ering ering3'>";
//html+="<div class='ering ering4'>";*/
html+="<div>";
html+=item_container({shade:shade,cid:'sitem',s_op:0.4,draggable:false,droppable:true});
html+="</div>";
//html+="</div>";
/*html+="</div>";
html+="</div>";
html+="</div>";*/
html+="<div style='margin-top: 12px'><div class='gamebutton clickable' onclick='"+f+"()'>"+button+"</div></div>";
html+="</div>";
$("#topleftcornerui").html(html);
if(!inventory) render_inventory(),inventory_opened_for=topleft_npc;
}

function render_recipe(element,type,name)
{
last_selector="#recipe-item";
Expand Down Expand Up @@ -3741,6 +3765,17 @@ function on_rclick(current)
$("#citem"+inum).parent().html("");
$("#litem").html(html);
}
else if(topleft_npc=="scrollsmith")
{
var current=character.items[inum],def=null;
if(current) def=G.items[current.name];
if(!def) return;
if(s_item!==null) return;
s_item=inum; cache_i[inum]=-1;
var html=$("#citem"+inum).all_html();
$("#citem"+inum).parent().html("");
$("#sitem").html(html);
}
else if(topleft_npc=="upgrade")
{
var current=character.items[inum],def=null;
Expand Down Expand Up @@ -4634,6 +4669,11 @@ function render_interaction(type,sub_type,args)
html+="Lock - Prevents anything that can destroy an item, selling, upgrading, you name it! Seal - Locks the item in a way that unlocking it takes two days. Unlock - Frees it. Got it? Good. Cost? 250 big ones.";
html+="<span style='float: right; margin-top: 5px'><div class='slimbutton' onclick='render_locksmith(\"lock\")'>LOCK</div> <div class='slimbutton' onclick='render_locksmith(\"seal\")'>SEAL</div> <div class='slimbutton' onclick='render_locksmith(\"unlock\")'>UNLOCK</div></span>";
}
else if(type=="scrollsmith")
{
html+="De-stat an item. Give you back the scrolls used on the item, as though the item were level 0. Returns the item back to you along with scrolls. Got it? Good. Cost? Depends on the scroll. 10 times the value of the scrolls that will be returned to you.";
html+="<span style='float: right; margin-top: 5px'><div class='slimbutton' onclick='render_scrollsmith()'>DE-STAT</div></span>";
}
else if(type=="crafting")
{
html+="I can craft or dismantle items for you. Price differs from item to item. Check out my recipes if you are interested!";
Expand Down
44 changes: 44 additions & 0 deletions node/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -5585,6 +5585,50 @@ function init_io() {
resend(player, "reopen+nc+inv");
success_response({ num: num, cevent: true });
});

socket.on("destat", function (data) {
var player = players[socket.id];
var item = player.items[data.item_num];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable was num in the client-side function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

var def = G.items[item && item.name];
if (!player || player.user) {
return fail_response("cant_in_bank");
}
if (!player.computer && simple_distance(G.maps.desertland.ref.scrollsmith, player) > B.sell_dist) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probable use distance for consistency?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

simple_distance is consistent with locksmith, which I based the code on.

return fail_response("distance");
}
var item = player.items[data.num];
if (!item) {
return fail_response("no_item");
}
var def = G.items[item.name];
Comment on lines +5597 to +5601
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you redefine item and def? Am I missing something?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copied a lot of the code from socket.on("locksmith"), it seems there is duplicate code there too.

if (item.stat_type == null) {
return fail_response("scrollsmith_cant");
}
var scrolltype = item.stat_type + "scroll";
if (scrolltype == "mp_costscroll") {
scrolltype = "mpcostscroll";
Comment on lines +5605 to +5607
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you try with all scrolls to make sure they all follow the pattern except mpcostscroll?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

}
var scrolldef = G.items[scrolltype];
if (!scrolldef) {
return fail_response("scrollsmith_cant"); // Just in case there isn't actually an item associated with the scroll... should never happen, though.
}
var needed = [1, 10, 100, 1000, 9999, 9999, 9999];
var ograde = calculate_item_grade(def, { name: item.name, level: 0 });
var cost = needed[ograde] * scrolldef.g * 10;
if (player.gold < cost) {
return fail_response("gold_not_enough");
}
if (!can_add_items(player, list_to_pseudo_items([[needed[ograde], scrolltype]]))) {
return fail_response("inv_size");
}
player.gold -= cost;
add_item(player, scrolltype, { q: needed[ograde] });
delete item.stat_type;
socket.emit("game_response", { response: "scrollsmith_success", gold: cost });
player.citems[data.num] = cache_item(player.items[data.num]);
resend(player, "reopen+nc");
success_response();
});
socket.on("locksmith", function (data) {
var player = players[socket.id];
var item = player.items[data.item_num];
Expand Down