Samuel - unit json 3(spells, specunitactions)

Here i will list the apprentices and their learning tasks, so others also can follow how it goes.
Please DONT POST HERE any solutions on the given task earlier than the apprentice, you can ask questions from him tough.
Post Reply
Stratego (dev)
Site Admin
Posts: 15741
Joined: Fri Apr 25, 2014 9:28 pm

Samuel - unit json 3(spells, specunitactions)

Post by Stratego (dev) »

ok, next will be harder, spells and specunitactions

2 units to jsonize:
assassin and templar.
ids:
public static final int UNIT_ASSASSIN = 34;
public static final int UNIT_TEMPLAR = 35;

images: (see on bottom)


else if (u.type == UNIT_ASSASSIN){

u.fillTexts(c, "UNIT_ASSASSIN");
u.costTurn = 4;

u.sight = 5; //visiblity range
u.hpMax = 8; //health points
u.armorPierce = 0; //how big the armor against arrows
u.armorNormal = 0; //how big the armor against normal attack
u.power = 6; // u.power of its attack
u.rangeWalk = 3; // how far it can walk
u.canWalkHill = false;
u.canWalkForest = true;
u.canOccupyBuilding = false;
u.canBeCarried = true;
u.bonusHealing = 1; // if this unit have bonus when it is healed by an other unit. 1,1 means 10% bonus.
u.convertResistance = 1; // victim property: 0.2 = 20% -> if priest has 30% than 30 - 30*0,2 => priest has 26% to convert.
u.isStealthUnit = true; //not visible to enemy (with restrictions)
u.canSeeStealthUnits = true; //sees stealth units normally



u.haveBonusAgainst = new int[]{// "this" unit have bonus against these units
};

u.specUnitActions = new ESpecUnitAction[]{
ESpecUnitAction.STEALTH_UNIT,
ESpecUnitAction.STEALTH_CAN_SEE_STEALTH,
};

u.bestAgainstMeGround = am(U_CHEAP_INFANTRY_MELEE, U_CHEAP_ARCHERS);
u.bestAgainstMeWater = U_SHIP_ATTACK;
u.modifiers = new int[]{//"type"-s (TECH) that modifies its properties
EFFECT_POISONED_ARROWS,
};
u.builders = new int[]{ //is it built in a TC? or in an archery range? or a worker builds it?
UNIT_TC
};
u.races = new int[] { // only these races can build this
RacesLoader.RACE_HUMAN
};

}//typeif


else if (u.type == UNIT_TEMPLAR){

u.fillTexts(c, "UNIT_TEMPLAR");
u.costTurn = 6;

u.sight = 5; //visiblity range
//u.rangeAttack = 1; //attack range (what maximal range it can attack) (1 means only nearby unit)
u.hpMax = 32; //health points
u.armorPierce = 2; //how big the armor against arrows
u.armorNormal = 2; //how big the armor against normal attack
u.power = 10; // u.power of its attack
u.rangeWalk = 3; // how far it can walk
u.rangeHeal = 1; //healrange (what maximal range it can heal) (1 means only nearby unit)
u.healRate = 7; // how many HP healed by turn (by this healing unit)
u.canWalkHill = false;
u.canWalkForest = true;
u.canOccupyBuilding = true;
u.canBeCarried = true;
u.bonusHealing = 2; // if this unit have bonus when it is healed by an other unit. 1,1 means 10% bonus.
u.convertResistance = 1; // victim property: 0.2 = 20% -> if priest has 30% than 30 - 30*0,2 => priest has 26% to convert.

u.weaponEffects = new SparseIntArray();
u.weaponEffects.append(Unit.WEAPON_EFFECT_SLOT_SPELLCAST, ConstLoader.EFFECT_INSTANT_HEAL);
u.weaponEffectOptions = new SparseArray<int[]>();
u.weaponEffectOptions.put(Unit.WEAPON_EFFECT_SLOT_SPELLCAST,
new int[] {
ConstLoader.EFFECT_INSTANT_HEAL, //priest
ConstLoader.EFFECT_INSTANT_EXORCISM,
}
);



bonusG(u, am (U_BUILDINGS, U_ANTI_BUILDING_MACHINE, a (U_CHEAP_ARCHERS, UNIT_ASSASSIN)), 1f,
new Gb(a (U_CHEAP_ARCHERS, UNIT_ASSASSIN), 0.5f)
);
u.bestAgainstMeGround = a(U_MOUNTED_KNIGHTS, UNIT_DOUBLE_SWORDMAN, UNIT_IMPERIAL_SHIELDER, UNIT_WAR_ELEPHANT);

u.bestAgainstMeWater = U_SHIP_ATTACK;
u.builders = new int[]{ //is it built in a TC? or in an archery range? or a worker builds it?
UNIT_TC,
UNIT_BUILDING_BARRACKS
};
u.grantorShopItems = new int[]{ //"shop item"-s that is required to have/build this one
ShopItemLoader.ITEM_TEMPLAR,
};
u.modifiers = new int[]{//"type"-s (TECH) that modifies its properties
TECH_ARMOR_INFANTRY_LV1,
TECH_ARMOR_INFANTRY_LV2,
TECH_SWORD_LV1,
TECH_SWORD_LV2,
EFFECT_POISONED_ARROWS,
};

u.races = new int[] { // only these races can build this
RacesLoader.RACE_HUMAN
};


}//typeif


here you need to see only the
a) image name,
b) and the sounds used
c) any special "arrows" on any special ability (getFeatureSpriteID, in temlar case the HEALING)



public static class UiUnitAssassin extends Ui.UiUnit{

//The ones you have to change when creating new Unit type
public static String IMG_NAME = "32_unit_assassin.png";
@Override
public Unit getNewUnitInstance(WorldMap map){return new Unit(map, Units.UNIT_ASSASSIN);}

//the ones need no change when creating unit types
public static TextureHolder imgBuildable;
@Override
public TiledTextureRegion getImgTexture(EColors color){return imgBuildable.get(color);}

@Override
public String getImgName(){return IMG_NAME;}

@Override
public Integer getSoundPack(ESoundEvents event){
Integer result = null;
switch (event) {
case UNIT_SELECTED: result = SoundsDefLoader.SOUND_PACK_UNIT_SELECT_LAND_UNIT; break;
case UNIT_AFFIRM_MOVE: result = SoundsDefLoader.SOUND_PACK_UNIT_AFFIRM_LAND_UNIT; break;
case UNIT_ATTACK: result = SoundsDefLoader.SOUND_PACK_UNIT_ATTACK_SWING; break;
case UNIT_DAMAGE: result = SoundsDefLoader.SOUND_PACK_UNIT_DAMAGED_HUMAN; break;
}
return result;
}


public UiUnitAssassin() {
super();
}//UiUnitAssassin
}//UiUnitAssassin

public static class UiUnitTemplar extends Ui.UiUnit{

//The ones you have to change when creating new Unit type
public static String IMG_NAME = "32_unit_templar.png";
@Override
public Unit getNewUnitInstance(WorldMap map){return new Unit(map, Units.UNIT_TEMPLAR);}

//the ones need no change when creating unit types
public static TextureHolder imgBuildable;
@Override
public TiledTextureRegion getImgTexture(EColors color){return imgBuildable.get(color);}

@Override
public String getImgName(){return IMG_NAME;}

@Override
public Integer getSoundPack(ESoundEvents event){
Integer result = null;
switch (event) {
case UNIT_SELECTED: result = SoundsDefLoader.SOUND_PACK_UNIT_SELECT_LAND_UNIT; break;
case UNIT_AFFIRM_MOVE: result = SoundsDefLoader.SOUND_PACK_UNIT_AFFIRM_LAND_UNIT; break;
case UNIT_ATTACK: result = SoundsDefLoader.SOUND_PACK_UNIT_ATTACK_SWING; break;
case UNIT_DAMAGE: result = SoundsDefLoader.SOUND_PACK_UNIT_DAMAGED_HUMAN; break;
case UNIT_HEAL: result = SoundsDefLoader.SOUND_PACK_UNIT_HEAL; break;
}
return result;
}

@Override
public int getFeatureSpriteID(EUnitSpriteFeatureTypes type){
switch (type) {
case HEAL: return PreparedSpritesLoader.SPRITE_ARROW_HEAL;
}
return 0;
}

public UiUnitTemplar() {
super();
}//UiUnitTemplar
}//UiUnitTemplar
Stratego (dev)
Site Admin
Posts: 15741
Joined: Fri Apr 25, 2014 9:28 pm

Re: Samuel - unit json (spells, specunitactions)

Post by Stratego (dev) »

i separate these topics because units will be more steps to achieve the knowledge.
User avatar
samuelch
Posts: 1677
Joined: Thu May 01, 2014 7:43 am
Location: Batavia

Re: Samuel - unit json (spells, specunitactions)

Post by samuelch »

Assassin and themplar json.
Attachments
unit_assassin.json
(3.49 KiB) Downloaded 103 times
unit_themplar.json
(4.08 KiB) Downloaded 113 times
Stratego (dev)
Site Admin
Posts: 15741
Joined: Fri Apr 25, 2014 9:28 pm

Re: Samuel - unit json (spells, specunitactions)

Post by Stratego (dev) »

good job!

comments:

assassin:
- you placed it to u_infantry_mellee category, instead of the "cheap" one - i have posted in the "categories FAQ" the list of available categories in AOF.
- you have not placed there the specunitactions itrequires STEALTH_UNIT and STEALTH_CAN_SEE_STEALTH - see other jsons that have such property called "trnSpecUnitActions"
- instead of this: "trnModifiers":{"unitList":["EFFECT_POISONED_ARROWS"]},
- it should be this: "trnModifiers":{"categories":["EFFECT_POISONED_ARROWS"]},
(but is see it is not right in some jsons , so those might not work already in game... eg: in goblin spearman i believe he does not get the goblin buffs now)

templar:
- THE json is invalid, you have not cheked it with the validator
- the grantorshopitem reference is a numerical ID of the shopitem, this case it is "47" (you could not know it)
- the bonuses are not nicely aligned (taht way you would see the extra { characters.
- the modifiers line is the same as in assassin.


other than these it seems ok!

please fix these - thanks!
Stratego (dev)
Site Admin
Posts: 15741
Joined: Fri Apr 25, 2014 9:28 pm

Re: Samuel - unit json (spells, specunitactions)

Post by Stratego (dev) »

any proggress here?
Stratego (dev)
Site Admin
Posts: 15741
Joined: Fri Apr 25, 2014 9:28 pm

Re: Samuel - unit json (spells, specunitactions)

Post by Stratego (dev) »

How is it going?
Stratego (dev)
Site Admin
Posts: 15741
Joined: Fri Apr 25, 2014 9:28 pm

Re: Samuel - unit json (spells, specunitactions)

Post by Stratego (dev) »

Hi, are you about finish this lecture?
Post Reply

Return to “Under the Hood studies”