Esempio n. 1
0
bool Weapon::configureEvent(const pugi::xml_node& node)
{
	pugi::xml_attribute attr;
	if (!(attr = node.attribute("id"))) {
		std::cout << "[Error - Weapon::configureEvent] Weapon without id." << std::endl;
		return false;
	}
	id = pugi::cast<uint16_t>(attr.value());

	if ((attr = node.attribute("level"))) {
		level = pugi::cast<uint32_t>(attr.value());
	}

	if ((attr = node.attribute("maglv")) || (attr = node.attribute("maglevel"))) {
		magLevel = pugi::cast<uint32_t>(attr.value());
	}

	if ((attr = node.attribute("mana"))) {
		mana = pugi::cast<uint32_t>(attr.value());
	}

	if ((attr = node.attribute("manapercent"))) {
		manaPercent = pugi::cast<uint32_t>(attr.value());
	}

	if ((attr = node.attribute("soul"))) {
		soul = pugi::cast<uint32_t>(attr.value());
	}

	if ((attr = node.attribute("prem"))) {
		premium = attr.as_bool();
	}

	if ((attr = node.attribute("breakchance"))) {
		breakChance = std::min<uint8_t>(100, pugi::cast<uint16_t>(attr.value()));
	}

	if ((attr = node.attribute("action"))) {
		action = getWeaponAction(attr.as_string());
		if (action == WEAPONACTION_NONE) {
			std::cout << "[Warning - Weapon::configureEvent] Unknown action " << attr.as_string() << std::endl;
		}
	}

	if ((attr = node.attribute("enabled"))) {
		enabled = attr.as_bool();
	}

	if ((attr = node.attribute("unproperly"))) {
		wieldUnproperly = attr.as_bool();
	}

	std::list<std::string> vocStringList;
	for (pugi::xml_node vocationNode = node.first_child(); vocationNode; vocationNode = vocationNode.next_sibling()) {
		if (!(attr = vocationNode.attribute("name"))) {
			continue;
		}

		int32_t vocationId = g_vocations.getVocationId(attr.as_string());
		if (vocationId != -1) {
			vocWeaponMap[vocationId] = true;
			int32_t promotedVocation = g_vocations.getPromotedVocation(vocationId);
			if (promotedVocation != 0) {
				vocWeaponMap[promotedVocation] = true;
			}

			if (vocationNode.attribute("showInDescription").as_bool(true)) {
				vocStringList.push_back(asLowerCaseString(attr.as_string()));
			}
		}
	}
	range = Item::items[id].shootRange;

	std::string vocationString;
	for (const std::string& str : vocStringList) {
		if (!vocationString.empty()) {
			if (str != vocStringList.back()) {
				vocationString.push_back(',');
				vocationString.push_back(' ');
			} else {
				vocationString += " and ";
			}
		}

		vocationString += str;
		vocationString.push_back('s');
	}

	uint32_t wieldInfo = 0;
	if (getReqLevel() > 0) {
		wieldInfo |= WIELDINFO_LEVEL;
	}

	if (getReqMagLv() > 0) {
		wieldInfo |= WIELDINFO_MAGLV;
	}

	if (!vocationString.empty()) {
		wieldInfo |= WIELDINFO_VOCREQ;
	}

	if (isPremium()) {
		wieldInfo |= WIELDINFO_PREMIUM;
	}

	if (wieldInfo != 0) {
		ItemType& it = Item::items.getItemType(id);
		it.wieldInfo = wieldInfo;
		it.vocationString = vocationString;
		it.minReqLevel = getReqLevel();
		it.minReqMagicLevel = getReqMagLv();
	}

	configureWeapon(Item::items[id]);
	return true;
}
Esempio n. 2
0
void convertItems(void)
{
	int		i;
	uint32_t	count = 0;
	cnvList_t	*il;
	btitem_t	*b;
	uint8_t		spell;

	il 	= itemList_new();

	for (i = 0; i < 256; i++) {
		if (itemName[i][0] == 'x')
			continue;

		b = btitem_new();

		b->name		= bts_strcpy(itemName[i]);
		b->macro	= bts_strcpy(itemName[i]);
		str2macro(b->macro->buf);

		/* Item Type */
		b->type = itemType[i] & 0x0f;

		/* Item equippable-by flags */
		b->canEquip.warrior = IFBIT(itemEquipMask[i], 0x80, 1, 0);
		b->canEquip.wizard = IFBIT(itemEquipMask[i], 0x40, 1, 0);
		b->canEquip.sorcerer = IFBIT(itemEquipMask[i], 0x40, 1, 0);
		b->canEquip.conjurer = IFBIT(itemEquipMask[i], 0x40, 1, 0);
		b->canEquip.magician = IFBIT(itemEquipMask[i], 0x40, 1, 0);
		b->canEquip.rogue = IFBIT(itemEquipMask[i], 0x10, 1, 0);
		b->canEquip.bard = IFBIT(itemEquipMask[i], 0x08, 1, 0);
		b->canEquip.paladin = IFBIT(itemEquipMask[i], 0x04, 1, 0);
		b->canEquip.hunter = IFBIT(itemEquipMask[i], 0x02, 1, 0);
		b->canEquip.monk = IFBIT(itemEquipMask[i], 0x01, 1, 0);
		b->canEquip.archmage = IFBIT(itemEquipMask[i], 0x20, 1, 0);
		b->canEquip.chronomancer = IFBIT(itemEquipMask[i], 0x60, 1, 0);
		b->canEquip.geomancer = IFBIT(itemEquipMask[i], 0xe0, 1, 0);

		b->type = itemType[i] & 0x0f;
		b->eclass = itemType[i] & 0x0f;
		b->ieffect = itemEffectList[i];
		b->spAttack = itemType[i] >> 4;

		b->dmgBonus = itemArmWepBonus[i] >> 4;
		b->acBonus = itemArmWepBonus[i] & 0x0f;
		b->canUse = (itemSpell[i] != 0xff);
		b->hasCharges = (itemCountMax[i] != 0xff);
		b->rndCharges = ((itemCountMax[i] != 0xff) && (itemCountMax[i] > 1));

		spell = itemSpell[i];

		if (b->type == 1) {
			b->ndice = NDICE(itemDmgDice[i]);
			b->die = DIEVAL(itemDmgDice[i]);
		}

		b->combat = b->canUse;
		b->noncombat = b->canUse;

		if (spell != 255) {
			getTargetting(itemSpell[i], &b->targetting);
			if (spell < 125) {
				b->action	= getSpellAction(spell);
				b->use		= USE_CASTSPELL;
			} else if ((spell == 126) || (spell == 127)) {
				b->action	= getSpellAction(spell);
				b->use		= USE_MAKELIGHT;
			} else if (spell == 128) {
				b->action	= getSpellAction(20);
				b->use		= USE_ATEIT;
			} else if (spell == 129) {
				b->action	= getSpellAction(20);
				b->use		= USE_DRINK;
			} else if (spell == 130) {
				/*
				 * This spell is going to be implemented
				 * via an onUse method to the square with
				 * the default onUse to be cantFindUse
				 */
			} else if (spell == 131) {
				b->action	= getWeaponAction(
							getWeapIndex(i));
				b->use		= USE_CASTWEAPON;
			} else if (spell == 132) {
				b->action	= getFigurineAction(
							getFigIndex(i));
				b->use		= USE_FIGURINE;
			} else if (spell == 133) {
				b->action	= getWeaponAction(
							getWeapIndex(i));
				b->use		= USE_BREATH;
			} else if (spell == 134) {
				b->action	= getSpellAction(spell);
				b->use		= USE_REENERGIZE;
			}
				
		}

		cnvList_add(il, b);

	}

	itemList_to_json(il, mkJsonPath("items.json"));
	cnvList_free(il);

#if 0
	printf("static main() {\n");
	printf("auto eid;\n");
	printf("eid = GetEnum(\"itemName\");\n");
	for (i = 0; i < 256; i++) {
		btstring_t	*buf;

		if (itemName[i][0] == 'x')
			continue;

		buf = bts_strcpy(itemName[i]);
		str2macro(buf->buf);
		printf("AddConstEx(eid, \"item_%s\", %d, -1);\n", buf->buf, i);
		bts_free(buf);
	}
	printf("}\n");
#endif
}