v0.8.9 (Bugfixes + translations) released to Google Play!

Useful links
Source code of the game - Contribution guide - ATCS Editor - Translate the game on Weblate - Example walkthrough - Andor's Trail Directory - Join the Discord
Get the game (v0.8.9) from Google, F-Droid, our server, or itch.io

Offensive Item Workspace

Discussions of the development process of the game.
Post Reply
lord midnight
Posts: 104
Joined: Sat Feb 05, 2011 9:23 am
Location: Oz

Offensive Item Workspace

Post by lord midnight »

Im trying to figure out how to do an item that deals damage to the targeted monster instead of healing the character.

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
Last edited by lord midnight on Sat Mar 05, 2011 1:24 am, edited 3 times in total.
AND/OR's ...
Image
oskarwiksten
Captain Awesome
Posts: 368
Joined: Sat Jan 29, 2011 8:51 am
android_version: 2.3 - Gingerbread
Location: Stockholm, Sweden

Re: Offensive Item Workspace

Post by oskarwiksten »

For examples on how to damage the target, check out combatController.playerAttacks() , and the private static attack() on CombatController.

For info about whether the player is in combat currently, you can use world.model.uiSelections.isInCombat
World (or model) is readable most everywhere.

/Oskar
/Oskar
lord midnight
Posts: 104
Joined: Sat Feb 05, 2011 9:23 am
Location: Oz

Re: Offensive Item Workspace

Post by lord midnight »

is category 49 open? 13?
can I alter the meanings of the categories?

can I have break chance and such instead?
can I add to the number of 'slots'? can I have full weapon with effect codes and scrollID and such?

I will need to make a Status Effect Class or Status Effect Flag something or another. You said you wanted to do this anyway. Will make thread for Status Effects.
AND/OR's ...
Image
lord midnight
Posts: 104
Joined: Sat Feb 05, 2011 9:23 am
Location: Oz

Re: Offensive Item Workspace

Post by lord midnight »

I made some changes to useItem above, would this be a really easy way to do this ?

I was looking over the standard Item type declarations, tag, name attckprct, dmg, blckprct, I can do the spells so they all work from that set. Shall I modify ? Or use a custom status class ?
AND/OR's ...
Image
oskarwiksten
Captain Awesome
Posts: 368
Joined: Sat Jan 29, 2011 8:51 am
android_version: 2.3 - Gingerbread
Location: Stockholm, Sweden

Re: Offensive Item Workspace

Post by oskarwiksten »

Best would probably be to reuse the existing item stats, since they are supported by the item editor. But if you want to have a go at enhancing the editor, please do :)
/Oskar
lord midnight
Posts: 104
Joined: Sat Feb 05, 2011 9:23 am
Location: Oz

Re: Offensive Item Workspace

Post by lord midnight »

ok, I will be using the existing item templates for this and enhance useitem/applyitemeffect/etc.

This will give offensive items, or 'scrolls' that work quickly with the existing system, status effect will be their own thing, though perhaps some items can inflict statuses at some point. These items will be a bit more straightforward and not based on duration or such just yet. I should have something together in a day or so.
AND/OR's ...
Image
lord midnight
Posts: 104
Joined: Sat Feb 05, 2011 9:23 am
Location: Oz

Re: Offensive Item Workspace

Post by lord midnight »

ok I have a system pretty well worked out. Im going over the new status classes and itemtypecollection.

I see the template to use and most of what I need to sort out. I already have the stuff Im doing broken into targeting player and targeting monster. I'll go through the classes some more and get the change list and framework code done in a bit. Just got some time tonight.

I still dont see the target monster in the useitem methods and I know there will need to be a case switch for any custom functions needed. I have a list of several things to get going now that can be expanded on later. Im sorry for any delay.
AND/OR's ...
Image
lizardninja
Posts: 23
Joined: Mon Feb 21, 2011 3:31 pm

Re: Offensive Item Workspace

Post by lizardninja »

look at you! running around like a thief in the night, plastering your emblem on any forum that'll take it.. im starting to understand the name 'lord midnight' alot more now!
lord midnight
Posts: 104
Joined: Sat Feb 05, 2011 9:23 am
Location: Oz

Re: Offensive Item Workspace

Post by lord midnight »

ok, so I have the basic changes needed listed above. I looked through the files as I could, MVC is very new to me, like this week new. I basically saw a way to use the combat traits to make basic spells, with simple addition. these are meant to be very simple.

This covers the first several words without using the status system yet. The bottom half will use the new system because it has durations and such. The purpose of this is simply to let an item be used on the current target monster. If there is a better way to do that then use it, this is just what I came up with. Im still getting used to your system and how things work.

You could easily have a "Throwing Knife" this way instead, that wasnt a scroll needing an alternate filter for special methods, most opf the scrolls really arent, but this way was easier than trying to add another variable to the item class, like has_special_function, i just thought using the category was easier..You do need to add the actiontype ATTACKITEM

you should be able to mostly cut and paste that it from the first post as marked.


Im looking at the status effect classes next, Im still going over them, they are for recurring actions and durations, all of the first several houses I made elsewhere are static actions, they just happen once and stack as many as you want to spend, could be a "Net" that lowers blocking and all kinds of things as easy as it could be a scroll.

Anyway, the above code was my take on items targeting the next creature in combat.
If there is another way go for it. Next for this is every creature in the combat area, and multiple strikes to a target, seeing if its dead, and the remaining strikes to the next creature.
I also will be doing the next set of positive scrolls that use the new status effects.
AND/OR's ...
Image
Post Reply