Impact Vest
#--------------------------------------------------------------------------------------------
# Scripting stuff
#--------------------------------------------------------------------------------------------
extended:
tags:
#--------------------------------------------------------------------------------------------
# RuleItem tags
#--------------------------------------------------------------------------------------------
RuleItem:
#defense
ITEM_IMPACT_VEST: int
ITEM_RESIST_SLOT_INDEX: int
#--------------------------------------------------------------------------------------------
# RuleUnit tags
#--------------------------------------------------------------------------------------------
BattleUnit:
#resistances
UNIT_RESIST_ITEM_SLOT_1: int
#--------------------------------------------------------------------------------------------
# Scripts
#--------------------------------------------------------------------------------------------
scripts:
newTurnUnit:
- offset: 1
code: |
# Clear all unit resist types and minimums so resistance items can set again
unit.setTag Tag.UNIT_RESIST_ITEM_SLOT_1 0;
return;
newTurnItem:
- offset: 3
code: |
var ptre BattleUnit itemOwner;
var ptr RuleItem itemRuleset;
var int itemResistSlotIndex;
var int temp;
item.getOwner itemOwner;
# If no owner, skip script
if eq itemOwner null;
return;
end;
# Check the item's slot index; if it's already set on this unit, don't count this item
item.getRuleItem itemRuleset;
itemRuleset.getTag itemResistSlotIndex Tag.ITEM_RESIST_SLOT_INDEX;
if eq itemResistSlotIndex 1;
itemOwner.getTag temp Tag.UNIT_RESIST_ITEM_SLOT_1;
if eq temp 1;
return;
else;
itemOwner.setTag Tag.UNIT_RESIST_ITEM_SLOT_1 1;
end;
end;
return;
hitUnit:
- offset: 3
code: |
var ptre BattleItem vestItem;
var ptr RuleItem damagingRuleset;
var ptr RuleItem vestRuleset;
var ptr Tile attackerTile;
var ptr Tile unitTile;
var int attackerX;
var int attackerY;
var int attackerZ;
var int unitX;
var int unitY;
var int unitZ;
var int distanceTile;
var int vestArmor;
unit.getTag vestArmor Tag.UNIT_RESIST_ITEM_SLOT_1;
if eq vestArmor 0;
debug_log "Vest not found! aborting";
return power part side;
end;
debug_log "damaging_type equals:";
debug_log damaging_type;
if or eq damaging_type 0 eq damaging_type 6 eq damaging_type 8 eq damaging_type 9;
debug_log "Damage was Special,Stun,Acid or Smoke aborting...";
battle_game.flashMessage "Damage bypasses vest!";
return power part side;
end;
#This should only run IF the maximum distance is NOT exceeded (4 tiles right now)
attacker.getPosition.getX attackerX;
attacker.getPosition.getY attackerY;
attacker.getPosition.getZ attackerZ;
battle_game.getTile attackerTile attackerX attackerY attackerZ;
unit.getPosition.getX unitX;
unit.getPosition.getY unitY;
unit.getPosition.getZ unitZ;
battle_game.getTile unitTile unitX unitY unitZ;
attackerTile.getDistanceTile distanceTile unitTile;
debug_log distanceTile;
debug_log "Above were distanceTile and distanceVoxel";
if gt distanceTile 4;
debug_log "Distance was greater than 4!";
debug_log distanceTile;
return power part side;
end;
if or eq side SIDE_LEFT eq side SIDE_RIGHT; #33%
set vestArmor 3;
battle_game.flashMessage "Damage reduced by: 33%";
else eq side SIDE_UNDER; #20%
set vestArmor 5;
battle_game.flashMessage "Damage reduced by: 20%";
else eq side SIDE_REAR; #25%
battle_game.flashMessage "Damage reduced by: 25%";
set vestArmor 4;
else eq side SIDE_FRONT; #50%
battle_game.flashMessage "Damage reduced by: 50%";
set vestArmor 2;
end;
debug_log "first is original power, after is power after reductions";
debug_log power;
#We're only removing that percentage, not making the damage that percentage
div power vestArmor;
sub vestArmor 1;
mul power vestArmor;
debug_log power;
return power part side;
#--------------------------------------------------------------------------------------------
# Items
#--------------------------------------------------------------------------------------------
items:
#impact vest
- type: STR_IMPACT_VEST
size: 0.2
costBuy: 100000
costSell: 25000
weight: 2
bigSprite: 32 #check this
floorSprite: 32 #check this
battleType: 10
invWidth: 2
invHeight: 2
supportedInventorySections:
- STR_BACK_PACK
tags:
ITEM_IMPACT_VEST: 1
ITEM_RESIST_SLOT_INDEX: 1
This item is basically only able to be equipped in your backpack and when present will reduce damage under the condition the distance between your attacker is no more than 4, frontal attacks receive the full bonus while other sides have a lesser effect (50% for front, 33% for sides, 25% for back or something like that) Additionally any damage that isn't physical (Plasma, Laser, Smoke) is ignored, this takes inspiration from the Damage reduction items found in the X-Com Files, and actually uses some of the code to achieve the "assigning" part since otherwise you'd need to keep checking the unit's inventory