72 lines
1.9 KiB
Plaintext
72 lines
1.9 KiB
Plaintext
global.weapons = {};
|
|
#macro wp global.weapons
|
|
function weapon(name_, description_, type_, statmods=[]) constructor {
|
|
name = name_;
|
|
description = description_;
|
|
modifiers = {};
|
|
type = WPTYPE.SWORD;
|
|
var i;
|
|
for (i=0; i<array_length(statmods); i++) {
|
|
modifiers[$statmods[i].name] = statmods[i];
|
|
}
|
|
global.weapons[$name] = self;
|
|
}
|
|
|
|
enum WPTYPE {
|
|
NULL,
|
|
SWORD,
|
|
LEAF,
|
|
GUN,
|
|
}
|
|
|
|
function c_addweapon(target, weapon_, equip=false) {
|
|
//array_push(target.inventory, deep_copy(weapon_));
|
|
array_push(target.inventory, weapon_);
|
|
if equip {
|
|
target.equippedweapon = array_length(target.inventory)-1;
|
|
c_equipweapon(target, target.inventory[target.equippedweapon]);
|
|
}
|
|
}
|
|
|
|
function c_equipweapon(target, weapon_) {
|
|
log(target.data.str.val);
|
|
c_modifierreset(target);
|
|
log(target.data.str.val);
|
|
c_wpeval(target, weapon_);
|
|
log(target.data.str.val);
|
|
}
|
|
nu weapon("nothing", "it's literally nothing", WPTYPE.NULL);
|
|
nu weapon("knife", "bleed, bleed", WPTYPE.SWORD, [new statmod(st.str, 20, add)]);
|
|
|
|
function c_modifierreset(target) {
|
|
var dudes = variable_struct_get_names(target.data);
|
|
var lads = variable_struct_get_names(st);
|
|
var i;
|
|
for (i=0; i<array_length(dudes); i++) {
|
|
while !array_contains(lads, dudes[i]) || dudes[i] == "hp" {
|
|
array_delete(dudes, i, 1);
|
|
if i >= array_length(dudes) break;
|
|
}
|
|
if i >= array_length(dudes) break;
|
|
target.data[$dudes[i]].val = target.data[$dudes[i]].cap;
|
|
}
|
|
}
|
|
|
|
function c_wpeval(target, weapon_) {
|
|
var lads = variable_struct_get_names(target.data);
|
|
var dudes = variable_struct_get_names(weapon_.modifiers);
|
|
var i;
|
|
for (i=0; i<array_length(dudes); i++) {
|
|
if array_contains(lads, dudes[i]) {
|
|
target.data[$dudes[i]].val = weapon_.modifiers[$dudes[i]].operation(
|
|
target.data[$dudes[i]].val,
|
|
weapon_.modifiers[$dudes[i]].val
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
function c_statexists(target, statstring) {
|
|
var dudes = variable_struct_get_names(target.data);
|
|
return array_contains(dudes, statstring);
|
|
} |