/*This function adds a one time usable command, that is designed to permanently poison a weapon, add a chance
for instant death on a succesful hit, and grant some minor permanent bonuses on the weapon's creation. This bit
is added on act_obj.c, at the end. Don't forget to add the dofun.h part (COMMAND_FUN(do_bond) at the end of the
rest of the commands). A gsn_bond entry is needed in index.h as well.*/
Do_Fun(do_bond)
{
	char arg[MAX_STRING_LENGTH];
	ObjData *obj;
	AffectData af;
	int level = ch->level, skill = get_skill(ch, gsn_bond);
	argument = one_argument(argument, arg);
	obj = get_obj_list(ch, arg, ch->carrying_first);

	if (!IsNPC(ch) && skill < 1)
	{
		chprintln(ch, "You lack the training necessary to do that.");
		return;
	}
	
	if (NullStr(arg))
	{
		chprintln(ch, "Which weapon would you bond your blood with?");
		return;
	}
	
	if (obj == NULL)
	{
		chprintln(ch, "You don't have that weapon.");
		return;
	}
	
	if (obj->value[3] < 0
			|| attack_table[obj->value[3]].damage == DAM_BASH)
	{
		chprintln(ch, "You can only coat a bladed weapon with your blood.");
		return;
	}
	
	if (is_affected(ch, gsn_bond))/*If you've used this before (gaining the affect),
	you can't use it again. If you are poisoned by it, you can't use it either.*/
	{
		chprintln(ch, "Only by the grace of a divinity may you bond with more than one weapon.");
		return;
	}

	else if (IsWeaponStat(obj, WEAPON_BOND))
	{
		chprintln(ch, "It has already been made into a bondblade");
		return;
	}
	
	else if (!is_affected(ch, gsn_bond) && (!IsWeaponStat(obj, WEAPON_BOND)))
	{
		af.where = TO_AFFECTS;
		af.type = gsn_bond;
		af.level = (level * 3) / 2;
		af.duration = -1; /*This makes it a permanent affect.*/
		af.location = APPLY_DAMROLL;
		af.modifier = ch->level / 2;
		af.bitvector = AFF_BOND;
		affect_to_char(ch, &af);
		ch->max_hit /= 2;
		ch->hit = Min(ch->max_hit, ch->hit);
		ch->pcdata->perm_hit = ch->max_hit;
		af.where = TO_WEAPON;
		af.type = gsn_bond;
		af.level = level;
		af.duration = -1;
		af.location = APPLY_NONE;
		af.modifier = 0;
		af.bitvector = WEAPON_BOND;
		affect_to_obj(obj, &af);
		WaitState(ch, skill_table[gsn_bond].beats);
		chprintln(ch, "You coat the blade with your own blood, and utter a brief prayer.");
		act("$n caresses a blade while uttering a prayer.", ch, NULL, NULL, TO_ROOM);
		act("$p loses its metallic shine and its color becomes opaque.", ch, obj, NULL, TO_ALL);
		RemBit(obj->extra_flags, ITEM_GLOW);/*Creating a bondblade makes it opaque, so it stops glowing*/
		return;
	}
}
/*In fight.c the check for poisoning and instant death is made. This can be added after the 
if (ch->fighting == victim && IsWeaponStat(wield, WEAPON_VAMPIRIC)) check, or any of the weaponstat checks.*/
	if (ch->fighting == victim && (IsWeaponStat(wield, WEAPON_BOND)))
	{
		int level, diceroll = dice(1, 1000);
		AffectData *poison, af;
		poison = (affect_find(wield->affect_first, gsn_bond));
		level = poison->level;
		if (!saves_spell(level, victim, DAM_POISON) && diceroll == 1)
		{
			victim->hit = 1;
			dam = Max(99999, victim->max_hit);
			damage(ch, victim, dam, gsn_bond, DAM_NONE, false);
			chprintln(victim,
						  "You feel a deathly chill, but then you feel nothing at all.");
			chprintln(ch, "Your mark shivers once, then is still.");
			act("$N turns deathly pale, then falls to the ground!", victim, ch, NULL,
					TO_ROOM);
		}
		else if (!saves_spell(level, victim, DAM_POISON))
		{
			chprintln(victim,
					  "You feel a deathly chill as poison courses through your veins.");
			act("$n is poisoned by $p!", victim, wield, NULL,
				TO_NOTVICT);
			act("Your bondblade channels your energy to poison $N.", ch, NULL, victim, TO_CHAR);

			af.where = TO_AFFECTS;
			af.type = gsn_bond;
			af.level = level;
			af.duration = 1;
			af.location = APPLY_HIT;
			af.modifier = -5;
			af.bitvector = AFF_BOND;
			affect_join(victim, &af);
			ch->hit -= 2;
			ch->mana -= 2;
		}
	}
/*In order to keep bondblades really special, only assassins that _have_ the skill can use them. Add this
into void wear_obj on if (CanWear(obj, ITEM_WIELD)). This same bit will need to be added again on 
Do_Fun(do_second), right before act("$n wields $p in $s off-hand.", ch, obj, NULL, TO_ROOM); is a swell place
to add it. Email questions to riayi(at)gmail.com*/
		if (!is_affected(ch, gsn_bond) && IsWeaponStat(obj, WEAPON_BOND))
		{
			chprintln(ch, "You cannot wield a bondblade if you've not bonded with one yourself.");
			return;
		}