I have been reading the source, but Im still a bit lost, could someone step me through this use-case scenario, which classes are actively involved, combatview, combatcontroller for sure, what else, um even line numbers step by step. Im looking for a good place to put an 'attack item', in particular Id like to start with a Scroll of Mora, that deals 11 damage to the monster you are attacking, reading a scroll costs 5AP for now, good number to start from anyway...
I dont mind doing the work, but Im not quite sure yet where exactly to be looking, Ill keep going on my own. A big thing I dont see, is where the fact that you are in combat is listed for purposes of items.
Any help would be appreciated, if nothing else, we will have a method for using an item on the enemy in combat even if my proposed spell system is not used.
Please note this thread is just for the code mechanic, discussion of the spells is for the ideas section, this one is for hashing out the code.
Code: Select all
//changes needed to Item Class
public void useItem(ItemType type) {
if (!type.isUsable()) return;
final Player player = model.player;
final Actor target = determineNextMonster()/*some better way to do this? need stack for multitarget...*/
if (model.uiSelections.isInCombat) {
if (!player.useAPs(player.useItemCost)) return;
}
player.inventory.removeItem(type.id, 1);
if(type.isAttackItem) {
if (type.category = 13)
{
scrollSpecialEffect(target, type);
}
else applyAttackItem(player, type);
else{
applyUseEffect(player, type);
}
//TODO: provide feedback that the item has been used.
//context.mainActivity.message(androidContext.getResources().getString(R.string.inventory_item_used, type.name));
}
/*
ok basically with the item data I have you just
add the item traits to the target's combat traits
you use a switch case for the special effects of
specific spell words
*/
public void applyAttackItem(Actor target, ItemType item) {
//you can almost do target.combattraits += item.combattraits...
target.hp += item.hp;
target.combatTraits.attackCost += item.combatTraits.attackCost;
target.combatTraits.attackChance += item.combatTraits.attackChance;
target.combatTraits.criticalChance += item.combatTraits.criticalChance;
target.combatTraits.criticalMultiplier += item.combatTraits.criticalMultiplier;
target.combatTraits.damagePotential += item.combatTraits.damagePotential;
target.combatTraits.blockChance += item.combatTraits.blockChance;
target.combatTraits.damageResistance = (target.combatTraits.damageResistance/item.combatTraits.damageResistance)
}
public void scrollSpecialEffect(Actor target, ItemType item) {
switch(item.tag)
case scroll2: //morga
if(!target.ImmuneMortia)
{
if(rolld100<35) //use your d100!
{
target.hp - target.hp;
target.isDead = true;
}
}
break;
case scroll3: //mortia
if(!target.ImmuneMortia)
{
if(rolld100<65) //use your d100!
{
target.hp - target.hp;
target.isDead = true;
}
}
break;
//case
//final default case of the standard attack item system
//lets you filter out and apply things in the special cases
//then use the more common items.
applyAttackItem(target,item);
break;
}
//changes to ItemType
//USESCROLL,READSCROLL, USEATTACK, WATEVA, but it needs a new one
//just something to denote that this item works on monsters too.
public static final int ACTIONTYPE_ATTACKITEM = 3;
//need this to change target of items as right now they only work on player from
//inventory, alternatively you could change the way targeting is done,
//I thought this less intrusive
public boolean isAttackItem() { return actionType == ACTIONTYPE_ATTACKITEM; }
//EOF