#include <config.h>

inherit F_CLEAN_UP;

int do_drop(object me, object obj, int raw);

void create() { seteuid(getuid()); }

int main(object me, string arg) { object obj, *inv, obj2; int i, amount; mixed info; string item;

if (! arg)
	return notify_fail('你要丢下什么东西?\n');

if (sscanf(arg, "%d %s", amount, item) == 2)
{
	if (! objectp(obj = present(item, me)))
		return notify_fail('你身上没有这样东西。\n');

	if (wiz_level(me) < 3 && info = obj->query('no_drop'))
	//			return notify_fail(stringp(info) ? info : '这样东西不能丢弃。\n');
		return notify_fail( obj->name() + '不能被丢弃。\n');

	if (! obj->query_amount())
		return notify_fail( obj->name() + '不能被分开丢弃。\n');

	if (amount < 1)
		return notify_fail('你要丢弃至少一个物品。\n');

	if (amount > obj->query_amount())
		return notify_fail('你没有那么多的' + obj->name() + '。\n');
	else if (amount == (int)obj->query_amount())
		return do_drop(me, obj, 0);
	else
	{
		obj->set_amount((int)obj->query_amount() - amount);
		obj2 = new(base_name(obj));
		if (! objectp(obj2))
			return notify_fail('创建物品失败。\n');
		obj2->set_amount(amount);
		if (! do_drop(me, obj2, 0))
		{
			obj2->move(me);
			return 0;
		}
		return 1;
	}
}

return 0;

}

MUD 游戏中物品丢弃功能的代码分析及优化

原文地址: https://www.cveoy.top/t/topic/m5KN 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录