S Price: $0.902033 (+4.20%)

Contract Diff Checker

Contract Name:
FARPG_Simulated_DungeonV1

Contract Source Code:

File 1 of 1 : FARPG_Simulated_DungeonV1

// File: @openzeppelin/[email protected]/utils/Context.sol


// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)

pragma solidity ^0.8.0;

/**
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract Context {
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }
}

// File: @openzeppelin/[email protected]/access/Ownable.sol


// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)

pragma solidity ^0.8.0;


/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * By default, the owner account will be the one that deploys the contract. This
 * can later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract Ownable is Context {
    address private _owner;

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */
    constructor() {
        _transferOwnership(_msgSender());
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        _checkOwner();
        _;
    }

    /**
     * @dev Returns the address of the current owner.
     */
    function owner() public view virtual returns (address) {
        return _owner;
    }

    /**
     * @dev Throws if the sender is not the owner.
     */
    function _checkOwner() internal view virtual {
        require(owner() == _msgSender(), "Ownable: caller is not the owner");
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions anymore. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby removing any functionality that is only available to the owner.
     */
    function renounceOwnership() public virtual onlyOwner {
        _transferOwnership(address(0));
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        require(newOwner != address(0), "Ownable: new owner is the zero address");
        _transferOwnership(newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}

// File: FINALdeployFA/LIB - Common Structs.sol


pragma solidity ^0.8.9;
        
        
library S { 

//Pet struct
   
    struct Unit {
        uint hp; //unit fainted when hp <= 0
        uint attack; //attack - defense = damage on hp
        uint defense; //attack - defense = damage on hp
        uint speed; //how frequent to take a move
        uint intelligence; //how frequent to use skill
        uint genestrength; //depends on how many duplicates
        uint range; //range skill, id
        uint special; //special skill, id
    }

    struct Status {
        
        uint id; //unit id
        uint family; //determine which class of gear it can be wore. record while evolve, since its only has max 2 family, example Dragon+phantom, and 30gene max, so can use *100
       
        uint stage; //1 is rookie, 2 is mature, 3 is perfect
       
    }


    struct Time {
        uint bond; //how many time you took on this unit , use to evolve
        uint stamina; //how much you can train it per day. it should follow saturation graph
        uint hunger; //how much you feed it per day. it should follow saturation graph
    }


}
// File: FINALdeployFA/LIB - WeatherOutfit.sol


pragma solidity ^0.8.0;


library WO {


    function WeatherBuff (S.Unit[6] memory _UnitGroup, uint _weather) external pure returns (S.Unit[6] memory UnitGroup) {
        UnitGroup = _UnitGroup;
       
        for (uint i = 0; i < UnitGroup.length; i++) {
                if (_weather == 0 && (  UnitGroup[i].special == 3 || 
                                        UnitGroup[i].special == 5 || 
                                        UnitGroup[i].special == 10 || 
                                        UnitGroup[i].special == 23 || 
                                        UnitGroup[i].special == 28 || 
                                        UnitGroup[i].special == 38 || 
                                        UnitGroup[i].special == 39 || 
                                        UnitGroup[i].special == 60 || 
                                        UnitGroup[i].special == 63 || 
                                        UnitGroup[i].special == 69 || 
                                        UnitGroup[i].special == 81 || 
                                        UnitGroup[i].special == 95)) { //Fire
                    UnitGroup[i].attack = UnitGroup[i].attack*2;
                } else if (_weather == 0 && (   UnitGroup[i].special == 20 || 
                                                UnitGroup[i].special == 21 || 
                                                UnitGroup[i].special == 22 || 
                                                UnitGroup[i].special == 24 || 
                                                UnitGroup[i].special == 26 || 
                                                UnitGroup[i].special == 29 || 
                                                UnitGroup[i].special == 30 || 
                                                UnitGroup[i].special == 42 || 
                                                UnitGroup[i].special == 51 || 
                                                UnitGroup[i].special == 72 || 
                                                UnitGroup[i].special == 76 || 
                                                UnitGroup[i].special == 80 || 
                                                UnitGroup[i].special == 86 || 
                                                UnitGroup[i].special == 96)) { //Nature
                    UnitGroup[i].intelligence = UnitGroup[i].intelligence*2;
                } else if (_weather == 2 && (   UnitGroup[i].special == 15 || 
                                                UnitGroup[i].special == 17 || 
                                                UnitGroup[i].special == 31 || 
                                                UnitGroup[i].special == 35 || 
                                                UnitGroup[i].special == 71 || 
                                                UnitGroup[i].special == 75 || 
                                                UnitGroup[i].special == 79 || 
                                                UnitGroup[i].special == 98)) { //Water
                    UnitGroup[i].hp = (UnitGroup[i].hp*15)/10;
                } else if (_weather == 3 && (   UnitGroup[i].special == 2 || 
                                                UnitGroup[i].special == 4 || 
                                                UnitGroup[i].special == 27 || 
                                                UnitGroup[i].special == 55 || 
                                                UnitGroup[i].special == 57 || 
                                                UnitGroup[i].special == 62 || 
                                                UnitGroup[i].special == 73 || 
                                                UnitGroup[i].special == 85 || 
                                                UnitGroup[i].special == 87 || 
                                                UnitGroup[i].special == 97)) { //Electric
                    UnitGroup[i].speed = UnitGroup[i].speed*2;
                } else if (_weather == 4 && (   UnitGroup[i].special == 12 || 
                                                UnitGroup[i].special == 14 || 
                                                UnitGroup[i].special == 16 || 
                                                UnitGroup[i].special == 25 || 
                                                UnitGroup[i].special == 43 || 
                                                UnitGroup[i].special == 46 || 
                                                UnitGroup[i].special == 47 || 
                                                UnitGroup[i].special == 61 || 
                                                UnitGroup[i].special == 64 || 
                                                UnitGroup[i].special == 82)) { //Ice
                    UnitGroup[i].defense = UnitGroup[i].defense*2;
                } else if (_weather == 6 && (   UnitGroup[i].special == 8 || 
                                                UnitGroup[i].special == 9 || 
                                                UnitGroup[i].special == 11 || 
                                                UnitGroup[i].special == 18 || 
                                                UnitGroup[i].special == 32 || 
                                                UnitGroup[i].special == 33 || 
                                                UnitGroup[i].special == 36 || 
                                                UnitGroup[i].special == 44 || 
                                                UnitGroup[i].special == 54 || 
                                                UnitGroup[i].special == 56 || 
                                                UnitGroup[i].special == 58 || 
                                                UnitGroup[i].special == 70 || 
                                                UnitGroup[i].special == 74 || 
                                                UnitGroup[i].special == 78 || 
                                                UnitGroup[i].special == 84 || 
                                                UnitGroup[i].special == 88)) { //Dark
                    UnitGroup[i].hp = UnitGroup[i].hp*2;
                } else if (_weather == 5 && (   UnitGroup[i].special == 6 || 
                                                UnitGroup[i].special == 34 || 
                                                UnitGroup[i].special == 40 || 
                                                UnitGroup[i].special == 48 || 
                                                UnitGroup[i].special == 77 || 
                                                UnitGroup[i].special == 89 || 
                                                UnitGroup[i].special == 99)) { //Light
                    UnitGroup[i].speed = UnitGroup[i].speed*2;
                }
            }

    }

    
    function TrainersOutfitBonus (S.Unit[6] memory _UnitGroup, uint[5] memory _outfitsID, uint[5] memory _outfitBalance) 
                internal pure returns (S.Unit[6] memory UnitGroup) {
        //_outfit[0~4] is outfit ID for the trainer ID. (what to wear) ID 0 means wearing nothing
        //[0] = Aerobot  [1] = headgear  [2] = Body   [3] = Leggings  [4 = Boots
        UnitGroup = _UnitGroup;
        //convert Outfit balance into Multiplier
        for (uint i=0; i<5; i++) {
            if (_outfitBalance[i] >= 4096) {
                _outfitBalance[i] = 5;
            } else if (_outfitBalance[i] >= 512) {
                _outfitBalance[i] = 4;
            } else if (_outfitBalance[i] >= 64) {
                _outfitBalance[i] = 3;
            } else if (_outfitBalance[i] >= 8) {
                _outfitBalance[i] = 2;
            } else if (_outfitBalance[i] >= 1) {
                _outfitBalance[i] = 1;
            } //otherwise = 0, multiplier =0
        }
        S.Unit memory Bonus;

        //Get Bonus from each outfit
       //==========   AEROBOT ======================
        if (_outfitsID[0] == 3001) { //Bolt (Aerobot) //spd + 6
            Bonus.speed += (6 * _outfitBalance[0]);
        } else if (_outfitsID[0] == 3002) { //Pixi (Aerobot) //atk + 6
            Bonus.attack += (6 * _outfitBalance[0]);
        } else if (_outfitsID[0] == 3003) { //Finspark (Aerobot) //SPD + 10
            Bonus.speed += (10 * _outfitBalance[0]);
        } else if (_outfitsID[0] == 3004) { //Cyanite //ATK + 10
            Bonus.attack += (10 * _outfitBalance[0]);
        } else if (_outfitsID[0] == 3005) { //Daemon //all (20, 2, 2, 2, 1)
            Bonus.hp += (20 * _outfitBalance[0]);
            Bonus.attack += (2 * _outfitBalance[0]);
            Bonus.defense += (2 * _outfitBalance[0]);
            Bonus.speed += (2 * _outfitBalance[0]);
            Bonus.intelligence += (1 * _outfitBalance[0]);
        } else if (_outfitsID[0] == 3006) { //Skye //Int +4
            Bonus.intelligence += (4 * _outfitBalance[0]);
        } else if (_outfitsID[0] == 3007) { //Cocoon //int +3
            Bonus.intelligence += (3 * _outfitBalance[0]);
        } else if (_outfitsID[0] == 3008) { //Orbitron //Spd +8
            Bonus.speed += (8 * _outfitBalance[0]);
        } else if (_outfitsID[0] == 3009) { //Glide //Atk +8
            Bonus.attack += (8 * _outfitBalance[0]);
        } else if (_outfitsID[0] == 3010) { //Bolt Mark II //Def + 8
            Bonus.defense += (8 * _outfitBalance[0]);
        } else if (_outfitsID[0] == 3011) { //Lovey //Hp + 80
            Bonus.hp += (80 * _outfitBalance[0]);
        } else if (_outfitsID[0] == 3012) { //Zetabot //hp + 60
            Bonus.hp += (60 * _outfitBalance[0]);
        } else if (_outfitsID[0] == 3013) { //Roxie //def + 6
            Bonus.defense += (6 * _outfitBalance[0]);
        } else if (_outfitsID[0] == 3014) { //Puzzle //INT + 5
            Bonus.intelligence += (5 * _outfitBalance[0]);
        } else if (_outfitsID[0] == 3015) { //Aura //all (20, 2, 2, 2, 1)
            Bonus.hp += (20 * _outfitBalance[0]);
            Bonus.attack += (2 * _outfitBalance[0]);
            Bonus.defense += (2 * _outfitBalance[0]);
            Bonus.speed += (2 * _outfitBalance[0]);
            Bonus.intelligence += (1 * _outfitBalance[0]);
        } else if (_outfitsID[0] == 3016) { //Goldon //DEF + 10
            Bonus.defense += (10 * _outfitBalance[0]);
        } else if (_outfitsID[0] == 3017) { //Meteoron //HP + 100
            Bonus.hp += (100 * _outfitBalance[0]);
        }

       //==========   Headgear ======================
        if (_outfitsID[1] == 6001) { //headgear 1 //hp+50
            Bonus.hp += (50 * _outfitBalance[1]);
        } else if (_outfitsID[1] == 6002) { //headgear 2 //atk+3
            Bonus.attack += (3 * _outfitBalance[1]);
        } else if (_outfitsID[1] == 6003) { //headgear 3 //def+3
            Bonus.defense += (3 * _outfitBalance[1]);
        } else if (_outfitsID[1] == 6004) { //headgear 4 //spd+3
            Bonus.speed += (3 * _outfitBalance[1]);
        } else if (_outfitsID[1] == 6005) { //headgear 5 //int+1
            Bonus.intelligence += (1 * _outfitBalance[1]);
        } else if (_outfitsID[1] == 6006) { //headgear 6 //hp+60
            Bonus.hp += (60 * _outfitBalance[1]);
        } else if (_outfitsID[1] == 6007) { //headgear 7 //atk+6
            Bonus.attack += (6 * _outfitBalance[1]);
        } else if (_outfitsID[1] == 6008) { //headgear 8 //def+6
            Bonus.defense += (6 * _outfitBalance[1]);
        } else if (_outfitsID[1] == 6009) { //headgear 9 //spd+6
            Bonus.speed += (6 * _outfitBalance[1]);
        } else if (_outfitsID[1] == 6010) { //headgear 10 //int+3
            Bonus.intelligence += (3 * _outfitBalance[1]);
        } else if (_outfitsID[1] == 6011) { //headgear 11 //hp+80
            Bonus.hp += (80 * _outfitBalance[1]);
        } else if (_outfitsID[1] == 6012) { //headgear 12 //atk+8
            Bonus.attack += (8 * _outfitBalance[1]);
        } else if (_outfitsID[1] == 6013) { //headgear 13 //def+8
            Bonus.defense += (8 * _outfitBalance[1]);
        } else if (_outfitsID[1] == 6014) { //headgear 14 //spd+8
            Bonus.speed += (8 * _outfitBalance[1]);
        } else if (_outfitsID[1] == 6015) { //headgear 15 //int+4
            Bonus.intelligence += (4 * _outfitBalance[1]);
        } else if (_outfitsID[1] == 6016) { //headgear 16 //hp+100
            Bonus.hp += (100 * _outfitBalance[1]);
        } else if (_outfitsID[1] == 6017) { //headgear 17 //atk+10
            Bonus.attack += (10 * _outfitBalance[1]);
        } else if (_outfitsID[1] == 6018) { //headgear 18 //def+10
            Bonus.defense += (10 * _outfitBalance[1]);
        } else if (_outfitsID[1] == 6019) { //headgear 19 //spd+10
            Bonus.speed += (10 * _outfitBalance[1]);
        } else if (_outfitsID[1] == 6020) { //headgear 20 //int+5
            Bonus.intelligence += (5 * _outfitBalance[1]);
        }
        
        //==========   Body ======================
        if (_outfitsID[2] == 1001) { //Scholar (Body) //hp 50
            Bonus.hp += (50 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1002) { //Scholar (Body) //atk 3
            Bonus.attack += (3 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1003) { //Scholar (Body) //def 3
            Bonus.defense += (3 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1004) { //Scholar (Body) //spd 3
            Bonus.speed += (3 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1005) { //Scholar (Body) //int 1
            Bonus.intelligence += (1 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1006 || _outfitsID[2] == 1007) { //Scholar (Body) //all (10,1,1,1,1)
            Bonus.hp += (10 * _outfitBalance[2]);
            Bonus.attack += (1 * _outfitBalance[2]);
            Bonus.defense += (1 * _outfitBalance[2]);
            Bonus.speed += (1 * _outfitBalance[2]);
            Bonus.intelligence += (1 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1022) { //Love Embrace (Body) //hp 60
            Bonus.hp += (60 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1023) { //Love Embrace (Body) //atk 6
            Bonus.attack += (6 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1024) { //Love Embrace (Body) //def 6
            Bonus.defense += (6 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1025) { //Love Embrace (Body) //spd 6
            Bonus.speed += (6 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1026) { //Love Embrace (Body) //int 3
            Bonus.intelligence += (3 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1027 || _outfitsID[2] == 1028) { //Love Embrace (Body) //all (12,2,1,1,1)
            Bonus.hp += (12 * _outfitBalance[2]);
            Bonus.attack += (2 * _outfitBalance[2]);
            Bonus.defense += (1 * _outfitBalance[2]);
            Bonus.speed += (1 * _outfitBalance[2]);
            Bonus.intelligence += (1 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1043) { //Celestial Harmony (Body) //hp 80
            Bonus.hp += (80 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1044) { //Celestial Harmony (Body) //atk 8
            Bonus.attack += (8 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1045) { //Celestial Harmony (Body) //def 8
            Bonus.defense += (8 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1046) { //Celestial Harmony (Body) //spd 8
            Bonus.speed += (8 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1047) { //Celestial Harmony (Body) //int 4
            Bonus.intelligence += (4 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1048 || _outfitsID[2] == 1049) { //Celestial Harmony (Body) //all (16,2,2,1,1)
            Bonus.hp += (16 * _outfitBalance[2]);
            Bonus.attack += (2 * _outfitBalance[2]);
            Bonus.defense += (2 * _outfitBalance[2]);
            Bonus.speed += (1 * _outfitBalance[2]);
            Bonus.intelligence += (1 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1064) { //Cyber Strike (Body) //hp 80
            Bonus.hp += (80 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1065) { //Cyber Strike (Body) //atk 8
            Bonus.attack += (8 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1066) { //Cyber Strike (Body) //def 8
            Bonus.defense += (8 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1067) { //Cyber Strike (Body) //spd 8
            Bonus.speed += (8 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1068) { //Cyber Strike (Body) //int 4
            Bonus.intelligence += (4 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1069 || _outfitsID[2] == 1070) { //Cyber Strike (Body) //all (16,2,2,1,1)
            Bonus.hp += (16 * _outfitBalance[2]);
            Bonus.attack += (2 * _outfitBalance[2]);
            Bonus.defense += (2 * _outfitBalance[2]);
            Bonus.speed += (1 * _outfitBalance[2]);
            Bonus.intelligence += (1 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1085) { //Serpent Tribe (Body) //hp 50
            Bonus.hp += (50 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1086) { //Serpent Tribe (Body) //atk 3
            Bonus.attack += (3 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1087) { //Serpent Tribe (Body) //def 3
            Bonus.defense += (3 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1088) { //Serpent Tribe (Body) //spd 3
            Bonus.speed += (3 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1089) { //Serpent Tribe (Body) //int 1
            Bonus.intelligence += (1 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1090 || _outfitsID[2] == 1091) { //Serpent Tribe (Body) //all (10,1,1,1,1)
            Bonus.hp += (10 * _outfitBalance[2]);
            Bonus.attack += (1 * _outfitBalance[2]);
            Bonus.defense += (1 * _outfitBalance[2]);
            Bonus.speed += (1 * _outfitBalance[2]);
            Bonus.intelligence += (1 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1106) { //Pearl Empress (Body) //hp 60
            Bonus.hp += (60 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1107) { //Pearl Empress (Body) //atk 6
            Bonus.attack += (6 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1108) { //Pearl Empress (Body) //def 6
            Bonus.defense += (6 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1109) { //Pearl Empress (Body) //spd 6
            Bonus.speed += (6 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1110) { //Pearl Empress (Body) //int 3
            Bonus.intelligence += (3 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1111 || _outfitsID[2] == 1112) { //Pearl Empress (Body) //all (12,2,1,1,1)
            Bonus.hp += (12 * _outfitBalance[2]);
            Bonus.attack += (2 * _outfitBalance[2]);
            Bonus.defense += (1 * _outfitBalance[2]);
            Bonus.speed += (1 * _outfitBalance[2]);
            Bonus.intelligence += (1 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1127) { //Starlight Diva (Body) //hp 100
            Bonus.hp += (100 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1128) { //Starlight Diva (Body) //atk 10
            Bonus.attack += (10 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1129) { //Starlight Diva (Body) //def 10
            Bonus.defense += (10 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1130) { //Starlight Diva (Body) //spd 10
            Bonus.speed += (10 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1131) { //Starlight Diva (Body) //int 5
            Bonus.intelligence += (5 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1132 || _outfitsID[2] == 1133) { //Starlight Diva (Body) //all (20,2,2,2,1)
            Bonus.hp += (20 * _outfitBalance[2]);
            Bonus.attack += (2 * _outfitBalance[2]);
            Bonus.defense += (2 * _outfitBalance[2]);
            Bonus.speed += (2 * _outfitBalance[2]);
            Bonus.intelligence += (1 * _outfitBalance[2]);
        }
        
        //========== Leggings======================
        if (_outfitsID[3] == 1008) { //Scholar (Leggings) //hp 50
            Bonus.hp += (50 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1009) { //Scholar (Leggings) //atk 3
            Bonus.attack += (3 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1010) { //Scholar (Leggings) //def 3
            Bonus.defense += (3 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1011) { //Scholar (Leggings) //spd 3
            Bonus.speed += (3 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1012) { //Scholar (Leggings) //int 1
            Bonus.intelligence += (1 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1013 || _outfitsID[3] == 1014) { //Scholar (Leggings) //all (10,1,1,1,1)
            Bonus.hp += (10 * _outfitBalance[3]);
            Bonus.attack += (1 * _outfitBalance[3]);
            Bonus.defense += (1 * _outfitBalance[3]);
            Bonus.speed += (1 * _outfitBalance[3]);
            Bonus.intelligence += (1 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1029) { //Love Embrace (Leggings) //hp 60
            Bonus.hp += (60 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1030) { //Love Embrace (Leggings) //atk 6
            Bonus.attack += (6 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1031) { //Love Embrace (Leggings) //def 6
            Bonus.defense += (6 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1032) { //Love Embrace (Leggings) //spd 6
            Bonus.speed += (6 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1033) { //Love Embrace (Leggings) //int 3
            Bonus.intelligence += (3 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1034 || _outfitsID[3] == 1035) { //Love Embrace (Leggings) //all (12,2,1,1,1)
            Bonus.hp += (12 * _outfitBalance[3]);
            Bonus.attack += (2 * _outfitBalance[3]);
            Bonus.defense += (1 * _outfitBalance[3]);
            Bonus.speed += (1 * _outfitBalance[3]);
            Bonus.intelligence += (1 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1050) { //Celestial Harmony (Leggings) //hp 80
            Bonus.hp += (80 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1051) { //Celestial Harmony (Leggings) //atk 8
            Bonus.attack += (8 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1052) { //Celestial Harmony (Leggings) //def 8
            Bonus.defense += (8 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1053) { //Celestial Harmony (Leggings) //spd 8
            Bonus.speed += (8 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1054) { //Celestial Harmony (Leggings) //int 4
            Bonus.intelligence += (4 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1055 || _outfitsID[3] == 1056) { //Celestial Harmony (Leggings) //all (16,2,2,1,1)
            Bonus.hp += (16 * _outfitBalance[3]);
            Bonus.attack += (2 * _outfitBalance[3]);
            Bonus.defense += (2 * _outfitBalance[3]);
            Bonus.speed += (1 * _outfitBalance[3]);
            Bonus.intelligence += (1 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1071) { //Cyber Strike (Leggings) //hp 80
            Bonus.hp += (80 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1072) { //Cyber Strike (Leggings) //atk 8
            Bonus.attack += (8 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1073) { //Cyber Strike (Leggings) //def 8
            Bonus.defense += (8 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1074) { //Cyber Strike (Leggings) //spd 8
            Bonus.speed += (8 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1075) { //Cyber Strike (Leggings) //int 4
            Bonus.intelligence += (4 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1076 || _outfitsID[3] == 1077) { //Cyber Strike (Leggings) //all (16,2,2,1,1)
            Bonus.hp += (16 * _outfitBalance[3]);
            Bonus.attack += (2 * _outfitBalance[3]);
            Bonus.defense += (2 * _outfitBalance[3]);
            Bonus.speed += (1 * _outfitBalance[3]);
            Bonus.intelligence += (1 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1092) { //Serpent Tribe (Leggings) //hp 50
            Bonus.hp += (50 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1093) { //Serpent Tribe (Leggings) //atk 3
            Bonus.attack += (3 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1094) { //Serpent Tribe (Leggings) //def 3
            Bonus.defense += (3 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1095) { //Serpent Tribe (Leggings) //spd 3
            Bonus.speed += (3 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1096) { //Serpent Tribe (Leggings) //int 1
            Bonus.intelligence += (1 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1097 || _outfitsID[3] == 1098) { //Serpent Tribe (Leggings) //all (10,1,1,1,1)
            Bonus.hp += (10 * _outfitBalance[3]);
            Bonus.attack += (1 * _outfitBalance[3]);
            Bonus.defense += (1 * _outfitBalance[3]);
            Bonus.speed += (1 * _outfitBalance[3]);
            Bonus.intelligence += (1 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1113) { //Pearl Empress (Leggings) //hp 60
            Bonus.hp += (60 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1114) { //Pearl Empress (Leggings) //atk 6
            Bonus.attack += (6 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1115) { //Pearl Empress (Leggings) //def 6
            Bonus.defense += (6 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1116) { //Pearl Empress (Leggings) //spd 6
            Bonus.speed += (6 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1117) { //Pearl Empress (Leggings) //int 3
            Bonus.intelligence += (3 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1118 || _outfitsID[3] == 1119) { //Pearl Empress (Leggings) //all (12,2,1,1,1)
            Bonus.hp += (12 * _outfitBalance[3]);
            Bonus.attack += (2 * _outfitBalance[3]);
            Bonus.defense += (1 * _outfitBalance[3]);
            Bonus.speed += (1 * _outfitBalance[3]);
            Bonus.intelligence += (1 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1134) { //Starlight Diva (Leggings) //hp 100
            Bonus.hp += (100 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1135) { //Starlight Diva (Leggings) //atk 10
            Bonus.attack += (10 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1136) { //Starlight Diva (Leggings) //def 10
            Bonus.defense += (10 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1137) { //Starlight Diva (Leggings) //spd 10
            Bonus.speed += (10 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1138) { //Starlight Diva (Leggings) //int 5
            Bonus.intelligence += (5 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1139 || _outfitsID[3] == 1140) { //Starlight Diva (Leggings) //all (20,2,2,2,1)
            Bonus.hp += (20 * _outfitBalance[3]);
            Bonus.attack += (2 * _outfitBalance[3]);
            Bonus.defense += (2 * _outfitBalance[3]);
            Bonus.speed += (2 * _outfitBalance[3]);
            Bonus.intelligence += (1 * _outfitBalance[3]);
        }

        //========== Boots======================
        if (_outfitsID[4] == 1015) { //Scholar (Boots) //hp 50
            Bonus.hp += (50 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1016) { //Scholar (Boots) //atk 3
            Bonus.attack += (3 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1017) { //Scholar (Boots) //def 3
            Bonus.defense += (3 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1018) { //Scholar (Boots) //spd 3
            Bonus.speed += (3 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1019) { //Scholar (Boots) //int 1
            Bonus.intelligence += (1 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1020 || _outfitsID[4] == 1021) { //Scholar (Boots) //all (10,1,1,1,1)
            Bonus.hp += (10 * _outfitBalance[4]);
            Bonus.attack += (1 * _outfitBalance[4]);
            Bonus.defense += (1 * _outfitBalance[4]);
            Bonus.speed += (1 * _outfitBalance[4]);
            Bonus.intelligence += (1 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1036) { //Love Embrace (Boots) //hp 60
            Bonus.hp += (60 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1037) { //Love Embrace (Boots) //atk 6
            Bonus.attack += (6 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1038) { //Love Embrace (Boots) //def 6
            Bonus.defense += (6 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1039) { //Love Embrace (Boots) //spd 6
            Bonus.speed += (6 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1040) { //Love Embrace (Boots) //int 3
            Bonus.intelligence += (3 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1041 || _outfitsID[4] == 1042) { //Love Embrace (Boots) //all (12,2,1,1,1)
            Bonus.hp += (12 * _outfitBalance[4]);
            Bonus.attack += (2 * _outfitBalance[4]);
            Bonus.defense += (1 * _outfitBalance[4]);
            Bonus.speed += (1 * _outfitBalance[4]);
            Bonus.intelligence += (1 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1057) { //Celestial Harmony (Boots) //hp 80
            Bonus.hp += (80 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1058) { //Celestial Harmony (Boots) //atk 8
            Bonus.attack += (8 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1059) { //Celestial Harmony (Boots) //def 8
            Bonus.defense += (8 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1060) { //Celestial Harmony (Boots) //spd 8
            Bonus.speed += (8 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1061) { //Celestial Harmony (Boots) //int 4
            Bonus.intelligence += (4 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1062 || _outfitsID[4] == 1063) { //Celestial Harmony (Boots) //all (16,2,2,1,1)
            Bonus.hp += (16 * _outfitBalance[4]);
            Bonus.attack += (2 * _outfitBalance[4]);
            Bonus.defense += (2 * _outfitBalance[4]);
            Bonus.speed += (1 * _outfitBalance[4]);
            Bonus.intelligence += (1 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1078) { //Cyber Strike (Boots) //hp 80
            Bonus.hp += (80 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1079) { //Cyber Strike (Boots) //atk 8
            Bonus.attack += (8 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1080) { //Cyber Strike (Boots) //def 8
            Bonus.defense += (8 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1081) { //Cyber Strike (Boots) //spd 8
            Bonus.speed += (8 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1082) { //Cyber Strike (Boots) //int 4
            Bonus.intelligence += (4 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1083 || _outfitsID[4] == 1084) { //Cyber Strike (Boots) //all (16,2,2,1,1)
            Bonus.hp += (16 * _outfitBalance[4]);
            Bonus.attack += (2 * _outfitBalance[4]);
            Bonus.defense += (2 * _outfitBalance[4]);
            Bonus.speed += (1 * _outfitBalance[4]);
            Bonus.intelligence += (1 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1099) { //Serpent Tribe (Boots) //hp 50
            Bonus.hp += (50 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1100) { //Serpent Tribe (Boots) //atk 3
            Bonus.attack += (3 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1101) { //Serpent Tribe (Boots) //def 3
            Bonus.defense += (3 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1102) { //Serpent Tribe (Boots) //spd 3
            Bonus.speed += (3 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1103) { //Serpent Tribe (Boots) //int 1
            Bonus.intelligence += (1 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1104 || _outfitsID[4] == 1105) { //Serpent Tribe (Boots) //all (10,1,1,1,1)
            Bonus.hp += (10 * _outfitBalance[4]);
            Bonus.attack += (1 * _outfitBalance[4]);
            Bonus.defense += (1 * _outfitBalance[4]);
            Bonus.speed += (1 * _outfitBalance[4]);
            Bonus.intelligence += (1 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1120) { //Pearl Empress (Boots) //hp 60
            Bonus.hp += (60 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1121) { //Pearl Empress (Boots) //atk 6
            Bonus.attack += (6 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1122) { //Pearl Empress (Boots) //def 6
            Bonus.defense += (6 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1123) { //Pearl Empress (Boots) //spd 6
            Bonus.speed += (6 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1124) { //Pearl Empress (Boots) //int 3
            Bonus.intelligence += (3 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1125 || _outfitsID[4] == 1126) { //Pearl Empress (Boots) //all (12,2,1,1,1)
            Bonus.hp += (12 * _outfitBalance[4]);
            Bonus.attack += (2 * _outfitBalance[4]);
            Bonus.defense += (1 * _outfitBalance[4]);
            Bonus.speed += (1 * _outfitBalance[4]);
            Bonus.intelligence += (1 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1141) { //Starlight Diva (Boots) //hp 100
            Bonus.hp += (100 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1142) { //Starlight Diva (Boots) //atk 10
            Bonus.attack += (10 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1143) { //Starlight Diva (Boots) //def 10
            Bonus.defense += (10 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1144) { //Starlight Diva (Boots) //spd 10
            Bonus.speed += (10 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1145) { //Starlight Diva (Boots) //int 5
            Bonus.intelligence += (5 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1146 || _outfitsID[4] == 1147) { //Starlight Diva (Boots) //all (20,2,2,2,1)
            Bonus.hp += (20 * _outfitBalance[4]);
            Bonus.attack += (2 * _outfitBalance[4]);
            Bonus.defense += (2 * _outfitBalance[4]);
            Bonus.speed += (2 * _outfitBalance[4]);
            Bonus.intelligence += (1 * _outfitBalance[4]);
        }

        for (uint i=0; i<3; i++) {
            if (UnitGroup[i].hp >0 ) { //not empty slot
                UnitGroup[i].hp = _UnitGroup[i].hp += Bonus.hp;
                UnitGroup[i].attack = _UnitGroup[i].attack += Bonus.attack;
                UnitGroup[i].defense = _UnitGroup[i].defense += Bonus.defense;
                UnitGroup[i].speed = _UnitGroup[i].speed += Bonus.speed;
                UnitGroup[i].intelligence = _UnitGroup[i].intelligence += Bonus.intelligence;
            }
           
        }

    }


    
    function readOutfitBonus (uint[5] memory _outfitsID, uint[5] memory _outfitBalance) 
                internal pure returns (S.Unit memory Bonus) {
        //_outfit[0~4] is outfit ID for the trainer ID. (what to wear) ID 0 means wearing nothing
        //[0] = Aerobot  [1] = headgear  [2] = Body   [3] = Leggings  [4 = Boots
        
        //convert Outfit balance into Multiplier
        for (uint i=0; i<5; i++) {
            if (_outfitBalance[i] >= 4096) {
                _outfitBalance[i] = 5;
            } else if (_outfitBalance[i] >= 512) {
                _outfitBalance[i] = 4;
            } else if (_outfitBalance[i] >= 64) {
                _outfitBalance[i] = 3;
            } else if (_outfitBalance[i] >= 8) {
                _outfitBalance[i] = 2;
            } else if (_outfitBalance[i] >= 1) {
                _outfitBalance[i] = 1;
            } //otherwise = 0, multiplier =0
        }

        //Get Bonus from each outfit
       //==========   AEROBOT ======================
        if (_outfitsID[0] == 3001) { //Bolt (Aerobot) //spd + 6
            Bonus.speed += (6 * _outfitBalance[0]);
        } else if (_outfitsID[0] == 3002) { //Pixi (Aerobot) //atk + 6
            Bonus.attack += (6 * _outfitBalance[0]);
        } else if (_outfitsID[0] == 3003) { //Finspark (Aerobot) //SPD + 10
            Bonus.speed += (10 * _outfitBalance[0]);
        } else if (_outfitsID[0] == 3004) { //Cyanite //ATK + 10
            Bonus.attack += (10 * _outfitBalance[0]);
        } else if (_outfitsID[0] == 3005) { //Daemon //all (20, 2, 2, 2, 1)
            Bonus.hp += (20 * _outfitBalance[0]);
            Bonus.attack += (2 * _outfitBalance[0]);
            Bonus.defense += (2 * _outfitBalance[0]);
            Bonus.speed += (2 * _outfitBalance[0]);
            Bonus.intelligence += (1 * _outfitBalance[0]);
        } else if (_outfitsID[0] == 3006) { //Skye //Int +4
            Bonus.intelligence += (4 * _outfitBalance[0]);
        } else if (_outfitsID[0] == 3007) { //Cocoon //int +3
            Bonus.intelligence += (3 * _outfitBalance[0]);
        } else if (_outfitsID[0] == 3008) { //Orbitron //Spd +8
            Bonus.speed += (8 * _outfitBalance[0]);
        } else if (_outfitsID[0] == 3009) { //Glide //Atk +8
            Bonus.attack += (8 * _outfitBalance[0]);
        } else if (_outfitsID[0] == 3010) { //Bolt Mark II //Def + 8
            Bonus.defense += (8 * _outfitBalance[0]);
        } else if (_outfitsID[0] == 3011) { //Lovey //Hp + 80
            Bonus.hp += (80 * _outfitBalance[0]);
        } else if (_outfitsID[0] == 3012) { //Zetabot //hp + 60
            Bonus.hp += (60 * _outfitBalance[0]);
        } else if (_outfitsID[0] == 3013) { //Roxie //def + 6
            Bonus.defense += (6 * _outfitBalance[0]);
        } else if (_outfitsID[0] == 3014) { //Puzzle //INT + 5
            Bonus.intelligence += (5 * _outfitBalance[0]);
        } else if (_outfitsID[0] == 3015) { //Aura //all (20, 2, 2, 2, 1)
            Bonus.hp += (20 * _outfitBalance[0]);
            Bonus.attack += (2 * _outfitBalance[0]);
            Bonus.defense += (2 * _outfitBalance[0]);
            Bonus.speed += (2 * _outfitBalance[0]);
            Bonus.intelligence += (1 * _outfitBalance[0]);
        } else if (_outfitsID[0] == 3016) { //Goldon //DEF + 10
            Bonus.defense += (10 * _outfitBalance[0]);
        } else if (_outfitsID[0] == 3017) { //Meteoron //HP + 100
            Bonus.hp += (100 * _outfitBalance[0]);
        }

       //==========   Headgear ======================
        if (_outfitsID[1] == 6001) { //headgear 1 //hp+50
            Bonus.hp += (50 * _outfitBalance[1]);
        } else if (_outfitsID[1] == 6002) { //headgear 2 //atk+3
            Bonus.attack += (3 * _outfitBalance[1]);
        } else if (_outfitsID[1] == 6003) { //headgear 3 //def+3
            Bonus.defense += (3 * _outfitBalance[1]);
        } else if (_outfitsID[1] == 6004) { //headgear 4 //spd+3
            Bonus.speed += (3 * _outfitBalance[1]);
        } else if (_outfitsID[1] == 6005) { //headgear 5 //int+1
            Bonus.intelligence += (1 * _outfitBalance[1]);
        } else if (_outfitsID[1] == 6006) { //headgear 6 //hp+60
            Bonus.hp += (60 * _outfitBalance[1]);
        } else if (_outfitsID[1] == 6007) { //headgear 7 //atk+6
            Bonus.attack += (6 * _outfitBalance[1]);
        } else if (_outfitsID[1] == 6008) { //headgear 8 //def+6
            Bonus.defense += (6 * _outfitBalance[1]);
        } else if (_outfitsID[1] == 6009) { //headgear 9 //spd+6
            Bonus.speed += (6 * _outfitBalance[1]);
        } else if (_outfitsID[1] == 6010) { //headgear 10 //int+3
            Bonus.intelligence += (3 * _outfitBalance[1]);
        } else if (_outfitsID[1] == 6011) { //headgear 11 //hp+80
            Bonus.hp += (80 * _outfitBalance[1]);
        } else if (_outfitsID[1] == 6012) { //headgear 12 //atk+8
            Bonus.attack += (8 * _outfitBalance[1]);
        } else if (_outfitsID[1] == 6013) { //headgear 13 //def+8
            Bonus.defense += (8 * _outfitBalance[1]);
        } else if (_outfitsID[1] == 6014) { //headgear 14 //spd+8
            Bonus.speed += (8 * _outfitBalance[1]);
        } else if (_outfitsID[1] == 6015) { //headgear 15 //int+4
            Bonus.intelligence += (4 * _outfitBalance[1]);
        } else if (_outfitsID[1] == 6016) { //headgear 16 //hp+100
            Bonus.hp += (100 * _outfitBalance[1]);
        } else if (_outfitsID[1] == 6017) { //headgear 17 //atk+10
            Bonus.attack += (10 * _outfitBalance[1]);
        } else if (_outfitsID[1] == 6018) { //headgear 18 //def+10
            Bonus.defense += (10 * _outfitBalance[1]);
        } else if (_outfitsID[1] == 6019) { //headgear 19 //spd+10
            Bonus.speed += (10 * _outfitBalance[1]);
        } else if (_outfitsID[1] == 6020) { //headgear 20 //int+5
            Bonus.intelligence += (5 * _outfitBalance[1]);
        }
        
        //==========   Body ======================
        if (_outfitsID[2] == 1001) { //Scholar (Body) //hp 50
            Bonus.hp += (50 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1002) { //Scholar (Body) //atk 3
            Bonus.attack += (3 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1003) { //Scholar (Body) //def 3
            Bonus.defense += (3 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1004) { //Scholar (Body) //spd 3
            Bonus.speed += (3 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1005) { //Scholar (Body) //int 1
            Bonus.intelligence += (1 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1006 || _outfitsID[2] == 1007) { //Scholar (Body) //all (10,1,1,1,1)
            Bonus.hp += (10 * _outfitBalance[2]);
            Bonus.attack += (1 * _outfitBalance[2]);
            Bonus.defense += (1 * _outfitBalance[2]);
            Bonus.speed += (1 * _outfitBalance[2]);
            Bonus.intelligence += (1 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1022) { //Love Embrace (Body) //hp 60
            Bonus.hp += (60 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1023) { //Love Embrace (Body) //atk 6
            Bonus.attack += (6 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1024) { //Love Embrace (Body) //def 6
            Bonus.defense += (6 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1025) { //Love Embrace (Body) //spd 6
            Bonus.speed += (6 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1026) { //Love Embrace (Body) //int 3
            Bonus.intelligence += (3 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1027 || _outfitsID[2] == 1028) { //Love Embrace (Body) //all (12,2,1,1,1)
            Bonus.hp += (12 * _outfitBalance[2]);
            Bonus.attack += (2 * _outfitBalance[2]);
            Bonus.defense += (1 * _outfitBalance[2]);
            Bonus.speed += (1 * _outfitBalance[2]);
            Bonus.intelligence += (1 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1043) { //Celestial Harmony (Body) //hp 80
            Bonus.hp += (80 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1044) { //Celestial Harmony (Body) //atk 8
            Bonus.attack += (8 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1045) { //Celestial Harmony (Body) //def 8
            Bonus.defense += (8 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1046) { //Celestial Harmony (Body) //spd 8
            Bonus.speed += (8 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1047) { //Celestial Harmony (Body) //int 4
            Bonus.intelligence += (4 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1048 || _outfitsID[2] == 1049) { //Celestial Harmony (Body) //all (16,2,2,1,1)
            Bonus.hp += (16 * _outfitBalance[2]);
            Bonus.attack += (2 * _outfitBalance[2]);
            Bonus.defense += (2 * _outfitBalance[2]);
            Bonus.speed += (1 * _outfitBalance[2]);
            Bonus.intelligence += (1 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1064) { //Cyber Strike (Body) //hp 80
            Bonus.hp += (80 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1065) { //Cyber Strike (Body) //atk 8
            Bonus.attack += (8 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1066) { //Cyber Strike (Body) //def 8
            Bonus.defense += (8 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1067) { //Cyber Strike (Body) //spd 8
            Bonus.speed += (8 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1068) { //Cyber Strike (Body) //int 4
            Bonus.intelligence += (4 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1069 || _outfitsID[2] == 1070) { //Cyber Strike (Body) //all (16,2,2,1,1)
            Bonus.hp += (16 * _outfitBalance[2]);
            Bonus.attack += (2 * _outfitBalance[2]);
            Bonus.defense += (2 * _outfitBalance[2]);
            Bonus.speed += (1 * _outfitBalance[2]);
            Bonus.intelligence += (1 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1085) { //Serpent Tribe (Body) //hp 50
            Bonus.hp += (50 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1086) { //Serpent Tribe (Body) //atk 3
            Bonus.attack += (3 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1087) { //Serpent Tribe (Body) //def 3
            Bonus.defense += (3 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1088) { //Serpent Tribe (Body) //spd 3
            Bonus.speed += (3 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1089) { //Serpent Tribe (Body) //int 1
            Bonus.intelligence += (1 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1090 || _outfitsID[2] == 1091) { //Serpent Tribe (Body) //all (10,1,1,1,1)
            Bonus.hp += (10 * _outfitBalance[2]);
            Bonus.attack += (1 * _outfitBalance[2]);
            Bonus.defense += (1 * _outfitBalance[2]);
            Bonus.speed += (1 * _outfitBalance[2]);
            Bonus.intelligence += (1 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1106) { //Pearl Empress (Body) //hp 60
            Bonus.hp += (60 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1107) { //Pearl Empress (Body) //atk 6
            Bonus.attack += (6 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1108) { //Pearl Empress (Body) //def 6
            Bonus.defense += (6 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1109) { //Pearl Empress (Body) //spd 6
            Bonus.speed += (6 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1110) { //Pearl Empress (Body) //int 3
            Bonus.intelligence += (3 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1111 || _outfitsID[2] == 1112) { //Pearl Empress (Body) //all (12,2,1,1,1)
            Bonus.hp += (12 * _outfitBalance[2]);
            Bonus.attack += (2 * _outfitBalance[2]);
            Bonus.defense += (1 * _outfitBalance[2]);
            Bonus.speed += (1 * _outfitBalance[2]);
            Bonus.intelligence += (1 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1127) { //Starlight Diva (Body) //hp 100
            Bonus.hp += (100 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1128) { //Starlight Diva (Body) //atk 10
            Bonus.attack += (10 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1129) { //Starlight Diva (Body) //def 10
            Bonus.defense += (10 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1130) { //Starlight Diva (Body) //spd 10
            Bonus.speed += (10 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1131) { //Starlight Diva (Body) //int 5
            Bonus.intelligence += (5 * _outfitBalance[2]);
        } else if (_outfitsID[2] == 1132 || _outfitsID[2] == 1133) { //Starlight Diva (Body) //all (20,2,2,2,1)
            Bonus.hp += (20 * _outfitBalance[2]);
            Bonus.attack += (2 * _outfitBalance[2]);
            Bonus.defense += (2 * _outfitBalance[2]);
            Bonus.speed += (2 * _outfitBalance[2]);
            Bonus.intelligence += (1 * _outfitBalance[2]);
        }
        
        //========== Leggings======================
        if (_outfitsID[3] == 1008) { //Scholar (Leggings) //hp 50
            Bonus.hp += (50 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1009) { //Scholar (Leggings) //atk 3
            Bonus.attack += (3 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1010) { //Scholar (Leggings) //def 3
            Bonus.defense += (3 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1011) { //Scholar (Leggings) //spd 3
            Bonus.speed += (3 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1012) { //Scholar (Leggings) //int 1
            Bonus.intelligence += (1 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1013 || _outfitsID[3] == 1014) { //Scholar (Leggings) //all (10,1,1,1,1)
            Bonus.hp += (10 * _outfitBalance[3]);
            Bonus.attack += (1 * _outfitBalance[3]);
            Bonus.defense += (1 * _outfitBalance[3]);
            Bonus.speed += (1 * _outfitBalance[3]);
            Bonus.intelligence += (1 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1029) { //Love Embrace (Leggings) //hp 60
            Bonus.hp += (60 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1030) { //Love Embrace (Leggings) //atk 6
            Bonus.attack += (6 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1031) { //Love Embrace (Leggings) //def 6
            Bonus.defense += (6 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1032) { //Love Embrace (Leggings) //spd 6
            Bonus.speed += (6 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1033) { //Love Embrace (Leggings) //int 3
            Bonus.intelligence += (3 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1034 || _outfitsID[3] == 1035) { //Love Embrace (Leggings) //all (12,2,1,1,1)
            Bonus.hp += (12 * _outfitBalance[3]);
            Bonus.attack += (2 * _outfitBalance[3]);
            Bonus.defense += (1 * _outfitBalance[3]);
            Bonus.speed += (1 * _outfitBalance[3]);
            Bonus.intelligence += (1 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1050) { //Celestial Harmony (Leggings) //hp 80
            Bonus.hp += (80 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1051) { //Celestial Harmony (Leggings) //atk 8
            Bonus.attack += (8 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1052) { //Celestial Harmony (Leggings) //def 8
            Bonus.defense += (8 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1053) { //Celestial Harmony (Leggings) //spd 8
            Bonus.speed += (8 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1054) { //Celestial Harmony (Leggings) //int 4
            Bonus.intelligence += (4 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1055 || _outfitsID[3] == 1056) { //Celestial Harmony (Leggings) //all (16,2,2,1,1)
            Bonus.hp += (16 * _outfitBalance[3]);
            Bonus.attack += (2 * _outfitBalance[3]);
            Bonus.defense += (2 * _outfitBalance[3]);
            Bonus.speed += (1 * _outfitBalance[3]);
            Bonus.intelligence += (1 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1071) { //Cyber Strike (Leggings) //hp 80
            Bonus.hp += (80 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1072) { //Cyber Strike (Leggings) //atk 8
            Bonus.attack += (8 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1073) { //Cyber Strike (Leggings) //def 8
            Bonus.defense += (8 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1074) { //Cyber Strike (Leggings) //spd 8
            Bonus.speed += (8 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1075) { //Cyber Strike (Leggings) //int 4
            Bonus.intelligence += (4 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1076 || _outfitsID[3] == 1077) { //Cyber Strike (Leggings) //all (16,2,2,1,1)
            Bonus.hp += (16 * _outfitBalance[3]);
            Bonus.attack += (2 * _outfitBalance[3]);
            Bonus.defense += (2 * _outfitBalance[3]);
            Bonus.speed += (1 * _outfitBalance[3]);
            Bonus.intelligence += (1 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1092) { //Serpent Tribe (Leggings) //hp 50
            Bonus.hp += (50 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1093) { //Serpent Tribe (Leggings) //atk 3
            Bonus.attack += (3 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1094) { //Serpent Tribe (Leggings) //def 3
            Bonus.defense += (3 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1095) { //Serpent Tribe (Leggings) //spd 3
            Bonus.speed += (3 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1096) { //Serpent Tribe (Leggings) //int 1
            Bonus.intelligence += (1 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1097 || _outfitsID[3] == 1098) { //Serpent Tribe (Leggings) //all (10,1,1,1,1)
            Bonus.hp += (10 * _outfitBalance[3]);
            Bonus.attack += (1 * _outfitBalance[3]);
            Bonus.defense += (1 * _outfitBalance[3]);
            Bonus.speed += (1 * _outfitBalance[3]);
            Bonus.intelligence += (1 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1113) { //Pearl Empress (Leggings) //hp 60
            Bonus.hp += (60 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1114) { //Pearl Empress (Leggings) //atk 6
            Bonus.attack += (6 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1115) { //Pearl Empress (Leggings) //def 6
            Bonus.defense += (6 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1116) { //Pearl Empress (Leggings) //spd 6
            Bonus.speed += (6 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1117) { //Pearl Empress (Leggings) //int 3
            Bonus.intelligence += (3 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1118 || _outfitsID[3] == 1119) { //Pearl Empress (Leggings) //all (12,2,1,1,1)
            Bonus.hp += (12 * _outfitBalance[3]);
            Bonus.attack += (2 * _outfitBalance[3]);
            Bonus.defense += (1 * _outfitBalance[3]);
            Bonus.speed += (1 * _outfitBalance[3]);
            Bonus.intelligence += (1 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1134) { //Starlight Diva (Leggings) //hp 100
            Bonus.hp += (100 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1135) { //Starlight Diva (Leggings) //atk 10
            Bonus.attack += (10 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1136) { //Starlight Diva (Leggings) //def 10
            Bonus.defense += (10 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1137) { //Starlight Diva (Leggings) //spd 10
            Bonus.speed += (10 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1138) { //Starlight Diva (Leggings) //int 5
            Bonus.intelligence += (5 * _outfitBalance[3]);
        } else if (_outfitsID[3] == 1139 || _outfitsID[3] == 1140) { //Starlight Diva (Leggings) //all (20,2,2,2,1)
            Bonus.hp += (20 * _outfitBalance[3]);
            Bonus.attack += (2 * _outfitBalance[3]);
            Bonus.defense += (2 * _outfitBalance[3]);
            Bonus.speed += (2 * _outfitBalance[3]);
            Bonus.intelligence += (1 * _outfitBalance[3]);
        }

        //========== Boots======================
        if (_outfitsID[4] == 1015) { //Scholar (Boots) //hp 50
            Bonus.hp += (50 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1016) { //Scholar (Boots) //atk 3
            Bonus.attack += (3 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1017) { //Scholar (Boots) //def 3
            Bonus.defense += (3 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1018) { //Scholar (Boots) //spd 3
            Bonus.speed += (3 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1019) { //Scholar (Boots) //int 1
            Bonus.intelligence += (1 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1020 || _outfitsID[4] == 1021) { //Scholar (Boots) //all (10,1,1,1,1)
            Bonus.hp += (10 * _outfitBalance[4]);
            Bonus.attack += (1 * _outfitBalance[4]);
            Bonus.defense += (1 * _outfitBalance[4]);
            Bonus.speed += (1 * _outfitBalance[4]);
            Bonus.intelligence += (1 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1036) { //Love Embrace (Boots) //hp 60
            Bonus.hp += (60 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1037) { //Love Embrace (Boots) //atk 6
            Bonus.attack += (6 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1038) { //Love Embrace (Boots) //def 6
            Bonus.defense += (6 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1039) { //Love Embrace (Boots) //spd 6
            Bonus.speed += (6 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1040) { //Love Embrace (Boots) //int 3
            Bonus.intelligence += (3 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1041 || _outfitsID[4] == 1042) { //Love Embrace (Boots) //all (12,2,1,1,1)
            Bonus.hp += (12 * _outfitBalance[4]);
            Bonus.attack += (2 * _outfitBalance[4]);
            Bonus.defense += (1 * _outfitBalance[4]);
            Bonus.speed += (1 * _outfitBalance[4]);
            Bonus.intelligence += (1 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1057) { //Celestial Harmony (Boots) //hp 80
            Bonus.hp += (80 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1058) { //Celestial Harmony (Boots) //atk 8
            Bonus.attack += (8 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1059) { //Celestial Harmony (Boots) //def 8
            Bonus.defense += (8 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1060) { //Celestial Harmony (Boots) //spd 8
            Bonus.speed += (8 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1061) { //Celestial Harmony (Boots) //int 4
            Bonus.intelligence += (4 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1062 || _outfitsID[4] == 1063) { //Celestial Harmony (Boots) //all (16,2,2,1,1)
            Bonus.hp += (16 * _outfitBalance[4]);
            Bonus.attack += (2 * _outfitBalance[4]);
            Bonus.defense += (2 * _outfitBalance[4]);
            Bonus.speed += (1 * _outfitBalance[4]);
            Bonus.intelligence += (1 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1078) { //Cyber Strike (Boots) //hp 80
            Bonus.hp += (80 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1079) { //Cyber Strike (Boots) //atk 8
            Bonus.attack += (8 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1080) { //Cyber Strike (Boots) //def 8
            Bonus.defense += (8 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1081) { //Cyber Strike (Boots) //spd 8
            Bonus.speed += (8 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1082) { //Cyber Strike (Boots) //int 4
            Bonus.intelligence += (4 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1083 || _outfitsID[4] == 1084) { //Cyber Strike (Boots) //all (16,2,2,1,1)
            Bonus.hp += (16 * _outfitBalance[4]);
            Bonus.attack += (2 * _outfitBalance[4]);
            Bonus.defense += (2 * _outfitBalance[4]);
            Bonus.speed += (1 * _outfitBalance[4]);
            Bonus.intelligence += (1 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1099) { //Serpent Tribe (Boots) //hp 50
            Bonus.hp += (50 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1100) { //Serpent Tribe (Boots) //atk 3
            Bonus.attack += (3 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1101) { //Serpent Tribe (Boots) //def 3
            Bonus.defense += (3 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1102) { //Serpent Tribe (Boots) //spd 3
            Bonus.speed += (3 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1103) { //Serpent Tribe (Boots) //int 1
            Bonus.intelligence += (1 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1104 || _outfitsID[4] == 1105) { //Serpent Tribe (Boots) //all (10,1,1,1,1)
            Bonus.hp += (10 * _outfitBalance[4]);
            Bonus.attack += (1 * _outfitBalance[4]);
            Bonus.defense += (1 * _outfitBalance[4]);
            Bonus.speed += (1 * _outfitBalance[4]);
            Bonus.intelligence += (1 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1120) { //Pearl Empress (Boots) //hp 60
            Bonus.hp += (60 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1121) { //Pearl Empress (Boots) //atk 6
            Bonus.attack += (6 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1122) { //Pearl Empress (Boots) //def 6
            Bonus.defense += (6 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1123) { //Pearl Empress (Boots) //spd 6
            Bonus.speed += (6 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1124) { //Pearl Empress (Boots) //int 3
            Bonus.intelligence += (3 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1125 || _outfitsID[4] == 1126) { //Pearl Empress (Boots) //all (12,2,1,1,1)
            Bonus.hp += (12 * _outfitBalance[4]);
            Bonus.attack += (2 * _outfitBalance[4]);
            Bonus.defense += (1 * _outfitBalance[4]);
            Bonus.speed += (1 * _outfitBalance[4]);
            Bonus.intelligence += (1 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1141) { //Starlight Diva (Boots) //hp 100
            Bonus.hp += (100 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1142) { //Starlight Diva (Boots) //atk 10
            Bonus.attack += (10 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1143) { //Starlight Diva (Boots) //def 10
            Bonus.defense += (10 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1144) { //Starlight Diva (Boots) //spd 10
            Bonus.speed += (10 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1145) { //Starlight Diva (Boots) //int 5
            Bonus.intelligence += (5 * _outfitBalance[4]);
        } else if (_outfitsID[4] == 1146 || _outfitsID[4] == 1147) { //Starlight Diva (Boots) //all (20,2,2,2,1)
            Bonus.hp += (20 * _outfitBalance[4]);
            Bonus.attack += (2 * _outfitBalance[4]);
            Bonus.defense += (2 * _outfitBalance[4]);
            Bonus.speed += (2 * _outfitBalance[4]);
            Bonus.intelligence += (1 * _outfitBalance[4]);
        }


    }






}
// File: @openzeppelin/contracts/security/ReentrancyGuard.sol


// OpenZeppelin Contracts (last updated v4.9.0) (security/ReentrancyGuard.sol)

pragma solidity ^0.8.0;

/**
 * @dev Contract module that helps prevent reentrant calls to a function.
 *
 * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
 * available, which can be applied to functions to make sure there are no nested
 * (reentrant) calls to them.
 *
 * Note that because there is a single `nonReentrant` guard, functions marked as
 * `nonReentrant` may not call one another. This can be worked around by making
 * those functions `private`, and then adding `external` `nonReentrant` entry
 * points to them.
 *
 * TIP: If you would like to learn more about reentrancy and alternative ways
 * to protect against it, check out our blog post
 * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
 */
abstract contract ReentrancyGuard {
    // Booleans are more expensive than uint256 or any type that takes up a full
    // word because each write operation emits an extra SLOAD to first read the
    // slot's contents, replace the bits taken up by the boolean, and then write
    // back. This is the compiler's defense against contract upgrades and
    // pointer aliasing, and it cannot be disabled.

    // The values being non-zero value makes deployment a bit more expensive,
    // but in exchange the refund on every call to nonReentrant will be lower in
    // amount. Since refunds are capped to a percentage of the total
    // transaction's gas, it is best to keep them low in cases like this one, to
    // increase the likelihood of the full refund coming into effect.
    uint256 private constant _NOT_ENTERED = 1;
    uint256 private constant _ENTERED = 2;

    uint256 private _status;

    constructor() {
        _status = _NOT_ENTERED;
    }

    /**
     * @dev Prevents a contract from calling itself, directly or indirectly.
     * Calling a `nonReentrant` function from another `nonReentrant`
     * function is not supported. It is possible to prevent this from happening
     * by making the `nonReentrant` function external, and making it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        _nonReentrantBefore();
        _;
        _nonReentrantAfter();
    }

    function _nonReentrantBefore() private {
        // On the first call to nonReentrant, _status will be _NOT_ENTERED
        require(_status != _ENTERED, "ReentrancyGuard: reentrant call");

        // Any calls to nonReentrant after this point will fail
        _status = _ENTERED;
    }

    function _nonReentrantAfter() private {
        // By storing the original value once again, a refund is triggered (see
        // https://eips.ethereum.org/EIPS/eip-2200)
        _status = _NOT_ENTERED;
    }

    /**
     * @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
     * `nonReentrant` function in the call stack.
     */
    function _reentrancyGuardEntered() internal view returns (bool) {
        return _status == _ENTERED;
    }
}

// File: FINALdeployFA/INTERFACE - StorageV2.sol


pragma solidity ^0.8.20;

// Import your custom structs


/**
 * @title IFARPG_Storage
 * @dev Interface for FARPG_Storage so other contracts can call it
 */
interface IFARPG_Storage {
    //-------------------------------------------------------------------------
    // Administrative / Master Contract Access
    //-------------------------------------------------------------------------
    function owner() external view returns (address);
    function masterContracts(uint index) external view returns (address);
    function masterIndex(address) external view returns (uint);
    function addMasterContract(address _address, uint _index) external;
    function addMasterContractBatch(address[] memory _addresses, uint[] memory _indices) external;
    function removeMasterContract(uint _index) external;
    function getAllMasterContracts() external view returns (address[] memory, uint[] memory);

    //-------------------------------------------------------------------------
    // UID Management
    //-------------------------------------------------------------------------
    function UIDmain(address) external view returns (uint);
    function UID_ownedby(uint) external view returns (address);
    function UIDcounter() external view returns (uint);
    function getUID(address player) external view returns (uint _UID);
    function transferUID(address player, address newplayerwallet) external;
    function registerUID(address player) external;

    function setUIDmain (address playerAddress, uint UID) external;
    function setUID_ownedby (uint UID, address playerAddress) external;

    //-------------------------------------------------------------------------
    // Quest (setters)
    //-------------------------------------------------------------------------
    function setMainQuest(address player, uint index, uint8 progress) external;
    function setSideQuest(address player, uint index, uint8 progress) external;
    function setPremiumScore(address player, uint score) external;
    function setPlayerGeneStrength(address player, uint index, uint strength) external;
    function setPlayerVitamin(address player, uint index, uint amount) external;

    //-------------------------------------------------------------------------
    // Quest (getters)
    //-------------------------------------------------------------------------
    function getMainQuestProgress(address player, uint index) external view returns (uint8);
    function getSideQuestProgress(address player, uint index) external view returns (uint8);
    function getPremiumScore(address player) external view returns (uint);
    function getPlayerQuestAndScore(address player, uint index) external view returns (uint, uint, uint);
    function getMainQuestProgressArray(address player) external view returns (uint8[64] memory);
    function getSideQuestProgressArray(address player) external view returns (uint8[64] memory);


    //-------------------------------------------------------------------------
    // Player Stats (setters)
    //-------------------------------------------------------------------------
    function setPersonalWallet(address player, address personal) external;
    function setGiveControlTo(address player, address web2wallet) external;
    function setExp(address player, uint experience) external;
    function setRankScore(address player, uint score) external;
    function setEnergy1(address player, uint energy) external;
    function setEnergy2(address player, uint energy) external;
    function setEnergy22(address player, uint energy) external;
    function setEnergy3(address player, uint energy) external;
    function setTeamFormat(address player, uint[60] calldata format) external;
    function setUsernameToUID(string memory username, uint _UID) external;
    function setUIDToUsername(uint _UID, string memory username) external;
    function deleteUsernameToAddress (string memory username) external;

    // Points
    function setPoint1(address player, uint point) external;
    function setPoint2(address player, uint point) external;
    function setPoint3(address player, uint point) external;
    function setPoint4(address player, uint point) external;
    function setPoint5(address player, uint point) external;
    function addPoint1(address player, uint point) external;
    function addPoint2(address player, uint point) external;
    function addPoint3(address player, uint point) external;
    function addPoint4(address player, uint point) external;
    function addPoint5(address player, uint point) external;

    //-------------------------------------------------------------------------
    // Player Stats (getters)
    //-------------------------------------------------------------------------
    function personalwallet(address) external view returns (address);
    function givecontrolto(address) external view returns (address);
    function getExperience(address player) external view returns (uint);
    function getRankingScore(address player) external view returns (uint);
    function getEnergy1(address player) external view returns (uint);
    function getEnergy2(address player) external view returns (uint);
    function getEnergy22(address player) external view returns (uint);
    function getEnergy3(address player) external view returns (uint);
    function getPlayerStats(address player) external view returns (uint, uint, uint, uint, uint, uint);
    function UIDToUsername(uint) external view returns (string memory);
    function usernameToUID(string memory) external view returns (uint);
    function getPoint1(address player) external view returns (uint);
    function getPoint2(address player) external view returns (uint);
    function getPoint3(address player) external view returns (uint);
    function getPoint4(address player) external view returns (uint);
    function getPoint5(address player) external view returns (uint);
    function getPlayerPoints(address player) external view returns (uint, uint, uint, uint, uint);
    function getPlayergenestrengthArray(address player) external view returns (uint[50] memory);
    function getPlayerGeneStrength(address player, uint index) external view returns (uint);
    function getPlayervitaminArray(address player) external view returns (uint[50] memory);
    function getPlayerVitamin(address player, uint index) external view returns (uint);
    //-------------------------------------------------------------------------
    // Limits (setters)
    //-------------------------------------------------------------------------
    function setLimit1(address player, uint limit) external;
    function setLimit2(address player, uint limit) external;
    function setLimit3(address player, uint limit) external;
    function setTimebound1(address player, uint timestamp) external;
    function setTimebound2(address player, uint timestamp) external;
    function setTimebound3(address player, uint timestamp) external;

    //-------------------------------------------------------------------------
    // Limits (getters)
    //-------------------------------------------------------------------------
    function getLimit1(address player) external view returns (uint);
    function getLimit2(address player) external view returns (uint);
    function getLimit3(address player) external view returns (uint);
    function getTimebound1(address player) external view returns (uint);
    function getTimebound2(address player) external view returns (uint);
    function getTimebound3(address player) external view returns (uint);
    function getPlayerLimits(address player) external view returns (uint, uint, uint, uint, uint, uint);

    //-------------------------------------------------------------------------
    // Numberset (setters)
    //-------------------------------------------------------------------------
    function setNumberSet1(address player, uint[6] memory number) external;
    function setNumberSet2(address player, uint[5] memory number) external;
    function setNumberSet3(address player, uint[5] memory number) external;
    function setNumberSet4(address player, uint[5] memory number) external;
    function setNumberSet5(address player, uint[5] memory number) external;
    function setNumberSet6(address player, uint[5] memory number) external;
    function setNumberSet7(address player, uint[5] memory number) external;
    function setNumberSet8(address player, uint[5] memory number) external;
    function setNumberSet9(address player, uint[5] memory number) external;
     function setNumberSetA(address player, uint[5] memory number) external; 
    function setNumberSetB(address player, uint[5] memory number) external; 
    function setNumberSetC(address player, uint[5] memory number) external; 
    function setNumberSetD(address player, uint[5] memory number) external; 
    function setNumberSetE(address player, uint[10] memory number) external; 
    function setNumberSetF(address player, uint[10] memory number) external; 
    function setNumberSetG(address player, uint[10] memory number) external; 
    function setNumberSetH(address player, uint[10] memory number) external;    

    //-------------------------------------------------------------------------
    // Numberset (getters)
    //-------------------------------------------------------------------------
    function getNumberSet1(address player) external view returns (uint[6] memory);
    function getNumberSet2(address player) external view returns (uint[5] memory);
    function getNumberSet3(address player) external view returns (uint[5] memory);
    function getNumberSet4(address player) external view returns (uint[5] memory);
    function getNumberSet5(address player) external view returns (uint[5] memory);
    function getNumberSet6(address player) external view returns (uint[5] memory);
    function getNumberSet7(address player) external view returns (uint[5] memory);
    function getNumberSet8(address player) external view returns (uint[5] memory);
    function getNumberSet9(address player) external view returns (uint[5] memory);
    function getNumberSetA(address player) external view returns (uint[5] memory);
    function getNumberSetB(address player) external view returns (uint[5] memory);
    function getNumberSetC(address player) external view returns (uint[5] memory);
    function getNumberSetD(address player) external view returns (uint[5] memory);
    function getNumberSetE(address player) external view returns (uint[10] memory);
    function getNumberSetF(address player) external view returns (uint[10] memory);
    function getNumberSetG(address player) external view returns (uint[10] memory);
    function getNumberSetH(address player) external view returns (uint[10] memory);
    
    //-------------------------------------------------------------------------
    // PVP Ranks
    //-------------------------------------------------------------------------
    struct Player {
        uint256 rankPoints;
        uint256 league;
        uint256 indexInLeague; // Index of the player within their league array
    }
    function setPlayers(address player, Player memory rankpointleagueindexinleague) external; 
    function setReset_Time_Attempts(address player, uint[2] memory resettimeattemps) external;  
    function setEligible_Opponents(address player, address[5] memory eligibleOppo) external;  
    function setFaught_Opponents(address player, uint[5] memory faughtOppo) external;  
    function setDefending_Formation(address player, uint[3] memory defendingslot) external;  
    function getPlayers(address player) external view returns (Player memory ) ;
    function getReset_Time_Attempts(address player ) external view returns (uint[2] memory );
    function getEligible_Opponents(address player  ) external view returns (address[5] memory);
    function getFaught_Opponents(address player ) external view returns(uint[5] memory) ;
    function getDefending_Formation(address player) external view returns (uint[3] memory );



    //-------------------------------------------------------------------------
    // Pet data (setters)
    //-------------------------------------------------------------------------
    function setPetUnits(address player, uint index, S.Unit memory newUnit) external;
    function setPetUnitsMaxVitamined(address player, uint index, S.Unit memory newUnit) external;
    function setPetStatuses(address player, uint index, S.Status memory newStatus) external;
    function setPetTimes(address player, uint index, S.Time memory newTime) external;

    //-------------------------------------------------------------------------
    // Pet data (getters)
    //-------------------------------------------------------------------------
    function getPetUnitsAll(address player) external view returns (S.Unit[500] memory);
    function getPetUnits(address player, uint _index) external view returns (S.Unit memory);
    function getPetUnitsMaxVitaminedAll(address player) external view returns (S.Unit[500] memory);
    function getPetUnitsMaxVitamined(address player, uint _index) external view returns (S.Unit memory);
    function getPetStatusesAll(address player) external view returns (S.Status[500] memory);
    function getPetStatuses(address player, uint _index) external view returns (S.Status memory);
    function getPetTimesAll(address player) external view returns (S.Time[500] memory);
    function getPetTimes(address player, uint _index) external view returns (S.Time memory);

    //-------------------------------------------------------------------------
    // Party / Outfit
    //-------------------------------------------------------------------------
    function setPartyFormation(address player, uint[30] memory slots) external;
    function setTrainerOutfitPosition(address player, uint[150] memory outfitIds) external;
    function getPartyFormation(address player) external view returns (uint[30] memory);
    function getAllOutfits(address player) external view returns (uint[150] memory);

    //-------------------------------------------------------------------------
    // Trainer Gene Infusing
    //-------------------------------------------------------------------------
    function setTrainerGeneInfusingGene(address player, uint index, uint value) external; 
    function setTrainerGeneInfusingGeneAll(address player, uint[50] memory newData) external;
    function setTrainerGeneInfusingTimer(address player, uint index, uint value) external; 
    function setTrainerGeneInfusingTimerAll(address player, uint[50] memory newData) external;

    function getTrainerGeneInfusingGeneAll(address player) external view returns (uint[50] memory) ;
    function getTrainerGeneInfusingTimerAll(address player) external view returns (uint[50] memory);
    function getTrainerGeneInfusingGene(address player, uint Index)external  view returns (uint ) ;
    function getTrainerGeneInfusingTimer(address player, uint Index)external  view returns (uint );


    //-------------------------------------------------------------------------
    // Additional Utility
    //-------------------------------------------------------------------------
    function getBattleUnit3(address player, uint[3] calldata slots)
        external
        view
        returns (S.Unit[3] memory Units3, uint[3] memory UnitIds);

    function getSlotUnitMore(address player, uint startindex, uint stopindex)
        external
        view
        returns (S.Unit[] memory Units, uint[] memory UnitIds);

    function getTeamFormat(address _addr) external view returns (uint[60] memory);

    //-------------------------------------------------------------------------
    // Weather System
    //-------------------------------------------------------------------------
    function getWeatherUnity() external view returns (uint _weather, uint _daylight, uint _blocktime);
    function getWeatherBattle(uint _timenow) external view returns (uint _weather);
    function setWeatherConstants(uint[12] memory _weatherIndices) external;
    function getWeatherIndexConstants() external view returns (uint[] memory);
}

// File: FINALdeployFA/PUBLIC - Simulated Dungeon V1.sol


pragma solidity ^0.8.9;

//_______________________________________________________________
//    ___ __   __     _   ___      _   ___    _ __  
//   | _ )\ \ / /  _ | | / _ \  _ | | / _ \  (_)\ \ 
//   | _ \ \ V /  | || || (_) || || || (_) |  _  | |
//   |___/  |_|    \__/  \___/  \__/  \___/  ( ) | |
//                                           |/ /_/ 
//_______________________________________________________________
//
//
// ____  _  _      _     _     ____  _____  _____ ____    ____  _     _      _____ _____ ____  _     
/// ___\/ \/ \__/|/ \ /\/ \   /  _ \/__ __\/  __//  _ \  /  _ \/ \ /\/ \  /|/  __//  __//  _ \/ \  /|
//|    \| || |\/||| | ||| |   | / \|  / \  |  \  | | \|  | | \|| | ||| |\ ||| |  _|  \  | / \|| |\ ||
//\___ || || |  ||| \_/|| |_/\| |-||  | |  |  /_ | |_/|  | |_/|| \_/|| | \||| |_//|  /_ | \_/|| | \||
//\____/\_/\_/  \|\____/\____/\_/ \|  \_/  \____\\____/  \____/\____/\_/  \|\____\\____\\____/\_/  \|
//                                                                                                  






// Interface for accessing Storage
//-------------------------------------------------------------------
//    _____ _   _ _______ ______ _____  ______      _____ ______ 
//   |_   _| \ | |__   __|  ____|  __ \|  ____/\   / ____|  ____|
//     | | |  \| |  | |  | |__  | |__) | |__ /  \ | |    | |__   
//     | | | . ` |  | |  |  __| |  _  /|  __/ /\ \| |    |  __|  
//    _| |_| |\  |  | |  | |____| | \ \| | / ____ \ |____| |____ 
//   |_____|_| \_|  |_|  |______|_|  \_\_|/_/    \_\_____|______|
//                                                          
//-------------------------------------------------------------------


interface BattleV4{
    function BattleV4_3v3 (S.Unit[6] memory _UnitGroup) external returns (uint , uint , bool , uint );
    function Calibrate (uint index) external returns (uint , uint , bool , uint );
}


interface FARPG_RAM2Interface {
    // Read functions
    function getWildUnit3 (uint[3] calldata wildLingsID) external pure returns (S.Unit[3] memory Units3);
    
}

interface WildLingsData_ERC1155Interface {
    // call functions 
    function mint( uint _amount, address _to, uint _id) external;
    function burn(address owner, uint _id, uint _amount) external ;
   
}
interface Items_ERC1155Interface {
    function balanceOfBatch(address[] memory accounts, uint256[] memory ids) external view returns (uint256[] memory);
    // call functions 
    function mint( uint _amount, address _to, uint _id) external;
    function burn(address owner, uint _id, uint _amount) external ;

}

contract FARPG_Simulated_DungeonV1 is Ownable, ReentrancyGuard {
    IFARPG_Storage public contractStorage;
    
    FARPG_RAM2Interface public contractRAM2;
    WildLingsData_ERC1155Interface public WildLingsDataNFT;
    BattleV4 public Battle;
    Items_ERC1155Interface public ItemsNFT;

    constructor() {
    }
    event StatChangedResult(S.Unit AfterUnit, S.Status AfterStatus, S.Time AfterTime);
//-------------------------------------------------------------------
//    _____ _      ____  ____          _       __      __    
//   / ____| |    / __ \|  _ \   /\   | |      \ \    / /    
//  | |  __| |   | |  | | |_) | /  \  | |       \ \  / /     
//  | | |_ | |   | |  | |  _ < / /\ \ | |        \ \/ /      
//  | |__| | |___| |__| | |_) / ____ \| |____     \  /     _ 
//   \_____|______\____/|____/_/    \_\______|     \/     (_)
//                                                                                                             
//-------------------------------------------------------------------
 
uint constant REENTRANT_TIMELIMIT = 2 seconds; // default 2 seconds. means u cannot run the nonreentrant functions >1 time within 3 seconds.
   

    mapping (address => uint) private reentrant_time;
    mapping (address => uint) private rewardreentrant_time;

    uint public REWARDMULTIPLIER = 100; //100 = 100%, reward will /100


    event BattleResultV2(uint BattleRythm, uint bit, bool Won, uint randret, S.Unit[6] unitgroup,uint[3] oponentid, uint[3] attackerid);

//--------------------------------------------------------- 
//                     _____  __  __ _____ _   _ 
//               /\   |  __ \|  \/  |_   _| \ | |
//              /  \  | |  | | \  / | | | |  \| |
//             / /\ \ | |  | | |\/| | | | | . ` |
//            / ____ \| |__| | |  | |_| |_| |\  |
//           /_/    \_\_____/|_|  |_|_____|_| \_|
//                                               
//---------------------------------------------------------             
    address public treasury = msg.sender; //default

    function updateTreasury(address _newTreasury) external onlyOwner {
        require(_newTreasury != address(0), "Invalid treasury address");
        treasury = _newTreasury;
    }                                  

    function updateStorageContractAAddress(address _newContractAAddress) external onlyOwner {
        require(_newContractAAddress != address(0), "Invalid address");
        contractStorage = IFARPG_Storage(_newContractAAddress);
    }
    
    function updateRAM2ContractAAddress(address _newContractAAddress) external onlyOwner {
        require(_newContractAAddress != address(0), "Invalid address");
        contractRAM2 = FARPG_RAM2Interface(_newContractAAddress);
    }
    function updateBattleV4Address(address _newContractAAddress) external onlyOwner {
        require(_newContractAAddress != address(0), "Invalid address");
        Battle = BattleV4(_newContractAAddress);
    }
    function updateWildLingsDataNFTAddress(address _newContractAAddress) external onlyOwner {
        require(_newContractAAddress != address(0), "Invalid address");
        WildLingsDataNFT = WildLingsData_ERC1155Interface(_newContractAAddress);
    }
    function updateItemNFTAddress(address _newContractAAddress) external onlyOwner {
        require(_newContractAAddress != address(0), "Invalid address");
        ItemsNFT = Items_ERC1155Interface(_newContractAAddress);
    }
    function withdraw() external onlyOwner {
        // Function to withdraw all balance from the contract for revenue
        require(address(this).balance > 0, "Contract balance is zero");
        payable(treasury).transfer(address(this).balance);
    }
//---------------------------------------------------------
//              
//             _____ _______       _____ _______ 
//            / ____|__   __|/\   |  __ \__   __|
//           | (___    | |  /  \  | |__) | | |   
//            \___ \   | | / /\ \ |  _  /  | |   
//            ____) |  | |/ ____ \| | \ \  | |   
//           |_____/   |_/_/    \_\_|  \_\ |_|   
//                                               
//---------------------------------------------------------                                     

//--------- sub functions ---------------
    function accountAddressToProceed() public view returns (address) {
    // Ready for account abstraction
    // If the player doesn't provide a personal wallet, all data will be recorded in the trainer wallet
    address playerAddress = contractStorage.personalwallet(msg.sender);
        if (playerAddress == address(0)) {
            return msg.sender;
        } else {
            return playerAddress;
        }
    }

    function subtract(uint256 a, uint256 b) internal pure returns (uint256) {
        require(b <= a, "SafeMath: subtraction overflow");
        return a - b;
    }
    
    modifier onlyEOA() {
        require(!isContract(msg.sender), "Smart contracts not allowed");
        _;
    }
    function noneReentrant_time(address player, uint timeSeconds) internal {
        //this is to prevent player spam an action or botting effectively.
        //this function must be Internal otherwise, it will congest a player reentrant time to make him/her unplayable
        require(block.timestamp - reentrant_time[player] >= timeSeconds,"Non-Reentrant, slow down TX attempts.");
        reentrant_time[player] = block.timestamp;
    }
    function isContract(address _addr) internal view returns (bool) {
        uint256 size;
        assembly {
            size := extcodesize(_addr)
        }
        return size > 0;
    }
    function forwardEtherToTreasury() internal {
        require(treasury != address(0), "Treasury address not set");
        (bool sent, ) = treasury.call{value: msg.value}("");
        require(sent, "Failed to forward Ether to treasury");
    }
    
    struct GameState {
            bool AttackerWin;
            uint bit;
            uint BattleRhythm;
            uint randret;
            uint weather;
            uint level;
            uint[6] numberSet1;
            uint[3] SimulatedLingsID;
    }
    function simulatedDungeonBattle(uint[3] calldata attackersSlots) public nonReentrant {
        address playerAddress = accountAddressToProceed();
      
        require(msg.sender.code.length == 0, "Only externally owned accounts are allowed.");
       
        
        GameState memory _gameState;
        S.Unit[3] memory TempUnits; //0,1,2 is Attacker
        //uint[3] memory AttackerIDs; //0,1,2 is Attacker
        S.Unit[6] memory UnitGroup; //this is a group that will send to battlecontract
        
        //get attacker data from player storage
        uint[3] memory AttackerIDs;
        (TempUnits,AttackerIDs) = contractStorage.getBattleUnit3(playerAddress,attackersSlots);
        require(TempUnits[0].hp>0 || TempUnits[1].hp>0 || TempUnits[2].hp>0,"3 empty slots, cannot battle.");
        UnitGroup[0] = TempUnits[0];
        UnitGroup[1] = TempUnits[1];
        UnitGroup[2] = TempUnits[2];
        //get opponent from wild Units
        (,_gameState.weather, _gameState.SimulatedLingsID,_gameState.numberSet1) = getNextLevel();
        //Simulated Dungeon [0]=difficulty now + lost matches, [1]=seed, [2]=time reload & attempts [3]=dungeon level [4]=difficulty max [5]=SD buff
        (TempUnits) = contractRAM2.getWildUnit3(_gameState.SimulatedLingsID);
        require(TempUnits[0].hp>0 || TempUnits[1].hp>0 || TempUnits[2].hp>0,"3 empty slots, cannot battle.");
        require(_gameState.numberSet1[5] <6000000000000000000000 &&  //need at least 20 '0, because each 4'0 give to buff percentage
            _gameState.numberSet1[1] > 0 && _gameState.numberSet1[3] <=3, "choose buff or Won Boss level." );
        UnitGroup[3] = TempUnits[0];
        UnitGroup[4] = TempUnits[1];
        UnitGroup[5] = TempUnits[2];
        //Add OutfitsBonus to Player
        UnitGroup = applyOutfitBonus(UnitGroup,playerAddress);
        //Add weather effects to all Lings.
        UnitGroup = WO.WeatherBuff(UnitGroup,_gameState.weather);
  
        uint _weight = ((_gameState.numberSet1[0]%1000000) + _gameState.numberSet1[3] )+7; //start with 70% so that to go 5, 6,.. and /10 later to get 10% resolution 
     
        UnitGroup[3].hp = (UnitGroup[3].hp * _weight)/10;
        UnitGroup[4].hp = (UnitGroup[4].hp * _weight)/10;
        UnitGroup[5].hp = (UnitGroup[5].hp * _weight)/10;
        UnitGroup[3].attack = (UnitGroup[3].attack * _weight)/10;
        UnitGroup[4].attack = (UnitGroup[4].attack * _weight)/10;
        UnitGroup[5].attack = (UnitGroup[5].attack * _weight)/10;
        UnitGroup[3].defense = (UnitGroup[3].defense * _weight)/10;
        UnitGroup[4].defense = (UnitGroup[4].defense * _weight)/10;
        UnitGroup[5].defense = (UnitGroup[5].defense * _weight)/10;
        UnitGroup[3].speed = (UnitGroup[3].speed * _weight)/10;
        UnitGroup[4].speed = (UnitGroup[4].speed * _weight)/10;
        UnitGroup[5].speed = (UnitGroup[5].speed * _weight)/10;
        UnitGroup[3].intelligence = (UnitGroup[3].intelligence * _weight)/10;
        UnitGroup[4].intelligence = (UnitGroup[4].intelligence * _weight)/10;
        UnitGroup[5].intelligence = (UnitGroup[5].intelligence * _weight)/10;

        //------------- SD bonus BUFF -------------
      
        _weight = _gameState.numberSet1[5] % 10000; // Get the last 4 digits
        UnitGroup[0].hp = (UnitGroup[0].hp * _weight)/10;
        UnitGroup[1].hp = (UnitGroup[1].hp * _weight)/10;
        UnitGroup[2].hp = (UnitGroup[2].hp * _weight)/10;
        _weight = (_gameState.numberSet1[5]/10000) % 10000; // Get the next 4 digits
        UnitGroup[0].attack = (UnitGroup[0].attack * _weight)/10;
        UnitGroup[1].attack = (UnitGroup[1].attack * _weight)/10;
        UnitGroup[2].attack = (UnitGroup[2].attack * _weight)/10;
        _weight = (_gameState.numberSet1[5]/100000000) % 10000;
        UnitGroup[0].defense = (UnitGroup[0].defense * _weight)/10;
        UnitGroup[1].defense = (UnitGroup[1].defense * _weight)/10;
        UnitGroup[2].defense = (UnitGroup[2].defense * _weight)/10;
        _weight = (_gameState.numberSet1[5]/1000000000000) % 10000;
        UnitGroup[0].speed = (UnitGroup[0].speed * _weight)/10;
        UnitGroup[1].speed = (UnitGroup[1].speed * _weight)/10;
        UnitGroup[2].speed = (UnitGroup[2].speed * _weight)/10;
        _weight = (_gameState.numberSet1[5]/10000000000000000) % 10000;
        UnitGroup[0].intelligence = (UnitGroup[0].intelligence * _weight)/10;
        UnitGroup[1].intelligence = (UnitGroup[1].intelligence * _weight)/10;
        UnitGroup[2].intelligence = (UnitGroup[2].intelligence * _weight)/10;

        (_gameState.BattleRhythm, _gameState.bit, _gameState.AttackerWin, _gameState.randret) = Battle.BattleV4_3v3(UnitGroup);
        if (_gameState.AttackerWin == true) {
            rewardNFT(playerAddress, _gameState.randret, _gameState.SimulatedLingsID, _gameState.numberSet1);
            //************************ SD SPECIFIC ************************
            if (_gameState.numberSet1[3] == 3) { //won Boss level
                if ((_gameState.numberSet1[0])%1000000 >  _gameState.numberSet1[4] ) { //current difficulty > max difficulty (%1000000 extract difficulty
                //plus 1
                _gameState.numberSet1[4] += 1;
                }
                //*********** Special Reward ********** Won Boss
                //reset the seed for buff to prevent prediction
                _gameState.numberSet1[1] = 0; //reset the seed back to 0, so getNextLevel() can works with Unity
            } else {
                _gameState.numberSet1[1] = (uint(keccak256(abi.encodePacked(block.timestamp, block.prevrandao,playerAddress))));
            }
            _gameState.numberSet1[3] += 1; // dungeon level + 1 (if seed set to 0, player cant battle in SD, so the rest doesn't matter )
            _gameState.numberSet1[5] += 6000000000000000000000; //set the buff number,  to make sure choose Bonus Buff to proceed next
            
            //*************************************************************
            contractStorage.setNumberSet1(playerAddress,_gameState.numberSet1);
        } else { //Lose = losing life, losing 5 lifes = lose dungeon, reset the seed back to 0, so getNextLevel() knows its game over
            
            _gameState.numberSet1[0] += 1000000; //add 1 losing match. combine with dificulty
            if (_gameState.numberSet1[0] >= 5000000) { //lost 5 times
                _gameState.numberSet1[1] = 0; //seed = 0, means reset
            }
            contractStorage.setNumberSet1(playerAddress,_gameState.numberSet1);
            
        }
        
        noneReentrant_time(playerAddress,5);//cannot battle between 8 seconds
        emit BattleResultV2(_gameState.BattleRhythm, _gameState.bit, _gameState.AttackerWin, _gameState.randret,UnitGroup,_gameState.SimulatedLingsID,AttackerIDs);

    }

    function chooseSDBuff(uint Choice) public nonReentrant {
        address playerAddress = accountAddressToProceed();
        noneReentrant_time(playerAddress,2);//cannot run again between X seconds
        require(Choice < 3, "invalid choice, needs < 3.");
        
        uint[6] memory _numberSet1 = contractStorage.getNumberSet1(playerAddress);
        require(_numberSet1[1] > 0 , "Won Boss Level, or havent win a level." ); //seed cannot be 0
        require(_numberSet1[5] >= 6000000000000000000000,"You need to won a dungeon level first.");

        _numberSet1[1] = (uint(keccak256(abi.encodePacked(block.timestamp, block.prevrandao,playerAddress))));
        //reset the seed for next level to prevent prediction

        uint[3] memory availableChoices = SDBuffChoices();
        _numberSet1[5] -= 6000000000000000000000; //reset the tangible SDBuff requirement to proceed next level
        uint buffnumber = availableChoices[Choice];
        uint weight;
      
        if (buffnumber <= 4) {
            weight = 5; //**********************5 means 50% will /10 in battle function
            _numberSet1[5] += (weight * (10000**(buffnumber%5)));
        } else if (buffnumber <= 5) {
            weight = 1; //**********************5 means 50% will /10 in battle function
            for (uint i=0; i<5; i++) {
                _numberSet1[5] += (weight * (10000**(i)));
            }
        } else if (buffnumber <= 10) {
            weight = 8; //**********************5 means 50% will /10 in battle function
             _numberSet1[5] += (weight * (10000**((buffnumber-1)%5))); //-1 because buffnumber:5 is +all stats, so buffnumber 6 start hp again
        } else if (buffnumber <= 11) {
            weight = 3; //**********************5 means 50% will /10 in battle function
            for (uint i=0; i<5; i++) {
                _numberSet1[5] += (weight * (10000**(i)));
            }
        } else if (buffnumber <= 16) {
            weight = 10; //**********************5 means 50% will /10 in battle function
            _numberSet1[5] += (weight * (10000**((buffnumber-2)%5)));//-2 because buffnumber:5,11 are +all stats, so buffnumber:12 start hp again
        } else if (buffnumber <= 17) {
            weight = 5; //**********************5 means 50% will /10 in battle function
            for (uint i=0; i<5; i++) {
                _numberSet1[5] += (weight * (10000**(i)));
            }
        }
        contractStorage.setNumberSet1(playerAddress,_numberSet1);
        
    }
    function SDBuffChoices() public view returns (uint[3] memory availableChoices) {
        address playerAddress = accountAddressToProceed();
       
        uint[6] memory _numberSet1 = contractStorage.getNumberSet1(playerAddress);
        uint seed = (_numberSet1[1]&65535)+5191;
        uint chance;
        seed += seed>>5;
        for(uint i = 0; i < 3; i++) {
            chance = seed % 10;
            
            if (chance < 7) { // small buff 70%
                seed += seed >> 5;
                availableChoices[i] = seed % 6;
            } else if (chance < 9) { // medium buff 20%
                seed += seed >> 5;
                availableChoices[i] = (seed % 6) + 6;
            } else { // big buff 10%
                seed += seed >> 5;
                availableChoices[i] = (seed % 6) + 12;
            }
            
        }
    }




    function applyOutfitBonus(S.Unit[6] memory _UnitGroup,address playerAddress) private view returns (S.Unit[6] memory UnitGroup) {
        uint[150] memory wearingOutfit = contractStorage.getAllOutfits(playerAddress);
        address[] memory addressBatch = new address[](5);
        uint256[] memory idsBatch = new uint256[](5);
        
        for (uint i = 0; i < 5; i++) {
            addressBatch[i] = playerAddress;
            idsBatch[i] = wearingOutfit[i];
        }
        
        uint256[] memory outfitBalance= new uint[](5);
        outfitBalance = ItemsNFT.balanceOfBatch(addressBatch, idsBatch);
        
        //convert to right type from dynamic
        uint[5] memory arrayID;
        uint[5] memory arrayBalance;
        for (uint i = 0; i < 5; i++) {
            arrayID[i] = idsBatch[i];
            arrayBalance[i] = outfitBalance[i];
        }
        UnitGroup = WO.TrainersOutfitBonus(_UnitGroup, arrayID, arrayBalance);
        
    }
    
    function rewardNFT(address playerAddress, uint randret, uint[3] memory wildLingsID, uint[6] memory numberSet1) internal {
   
        uint rewardCredit = 5+(numberSet1[0]%1000000);
        
        rewardCredit = (rewardCredit * 24 * REWARDMULTIPLIER) / 100;

        contractStorage.addPoint1(playerAddress,rewardCredit); 

      
        if (block.timestamp - reentrant_time[playerAddress] > 1) {
            rewardCredit = 6; //60% chance
        } else {
            rewardCredit = 3; //30% chance
        }
        for (uint i = 0; i < 3; i++) {
            if ((randret / (10**(i))) % 10 < rewardCredit) { 
                WildLingsDataNFT.mint(1, playerAddress, wildLingsID[i]);
            }
         
        } 

        uint rand = (uint(keccak256(abi.encodePacked(block.timestamp, block.prevrandao,playerAddress))));
       
        ItemsNFT.mint(1, playerAddress, ((rand%168) + 1001));
       
        if (numberSet1[3] == 3) { //Dungeon level = boss level
            uint chance = (numberSet1[0] %1000000) + 1; //also has chance even for difficulty = 0
            chance = (chance*100) / (chance+3) ;
            rand = rand/4096 + 61783;
            rand += rand;
            if (rand%100 < chance) { //success roll
              
                rand = rand/4096 + 61783;
                rand += rand;
                rand = rand % 37; 
                if (rand< 17) {
                  
                    chance = rand + 3001;
                } else { 
                    
                    chance = rand + 6000; 
                }
                ItemsNFT.mint(1, playerAddress, chance);
            }
        }
        


    }


    //based on the seed, get the next level / buff or 
    function getNextLevel () public view returns(uint map, uint weather, uint[3] memory SimulatedLingsID, uint[6] memory numberSet1) {
        address playerAddress = accountAddressToProceed();
       
        uint[6] memory _numberSet1 = contractStorage.getNumberSet1(playerAddress);
       
        numberSet1 = _numberSet1;
        weather = _numberSet1[1] % 7;
        if (_numberSet1[3] <= 2) { //dungeon level = 0,1,2
            map = ((_numberSet1[1]>>5) % 5)+1; //map 1~5 //No Imaginary
        
            if (map ==3) { map =2;} //give more chances to Lings available map
        } else { // dungeon level 3 (4th battle) Boss imaginary
            map = 6;
        }
        SimulatedLingsID[0] = (_numberSet1[1]>>10) % 16; //0~15
        SimulatedLingsID[1] = (_numberSet1[1]>>15) % 16; //0~15
        SimulatedLingsID[2] = (_numberSet1[1]>>20) % 16; //0~15
        if (map == 1 ) { //jungle //Wolf, Wombat
       
            for(uint i = 0; i < 3; i++) {
              
                if (SimulatedLingsID[i] < 3) {
                    SimulatedLingsID[i] = 44;//22;
                } else if (SimulatedLingsID[i] < 6) {
                    SimulatedLingsID[i] = 43;//23;
                } else if (SimulatedLingsID[i] < 9) {
                    SimulatedLingsID[i] = 44;//24;
                } else if (SimulatedLingsID[i] < 12) {
                    SimulatedLingsID[i] = 43;
                } else {
                    SimulatedLingsID[i] = 42;//44;
                }
            }            

        } else if (map == 2 ) { //Grassland //Qilin, Wolf
        //qilin 39 40, wolf 43 44, wolf qilin 81
            for(uint i = 0; i < 3; i++) {
              
                if (SimulatedLingsID[i] < 3) {
                    SimulatedLingsID[i] = 39;
                } else if (SimulatedLingsID[i] < 6) {
                    SimulatedLingsID[i] = 40;
                } else if (SimulatedLingsID[i] < 9) {
                    SimulatedLingsID[i] = 43;
                } else if (SimulatedLingsID[i] < 12) {
                    SimulatedLingsID[i] = 44;
                } else {
                    SimulatedLingsID[i] = 81;
                }
            }    
        
        } else if (map == 3 ) { //Graveyard // Wolf, Phantom //********TEMPORARY cancel Map3, so u cant get Map3. since all lings not released
        //  phantom   10 11 12 wolf phantom 78 phantom wombat 33 34
            for(uint i = 0; i < 3; i++) {
              
                if (SimulatedLingsID[i] < 3) {
                    SimulatedLingsID[i] = 10;
                } else if (SimulatedLingsID[i] < 6) { //********TEMPORARY cancel Map3, so u cant get Map3. since all lings not released
                    SimulatedLingsID[i] = 11;
                } else if (SimulatedLingsID[i] < 9) {
                    SimulatedLingsID[i] = 12;
                } else if (SimulatedLingsID[i] < 12) {
                    SimulatedLingsID[i] = 78;
                } else if (SimulatedLingsID[i] < 14) {
                    SimulatedLingsID[i] = 33;
                } else {
                    SimulatedLingsID[i] = 34;
                }
            }    

        } else if (map == 4 ) { //Beach  // Aqua, Wombat
        //aqua 16 17 18, wolf aqua 79, aqua wombat 35 36, 
            for(uint i = 0; i < 3; i++) {
              
                if (SimulatedLingsID[i] < 3) {
                    SimulatedLingsID[i] = 16;
                } else if (SimulatedLingsID[i] < 6) {
                    SimulatedLingsID[i] = 17;
                } else if (SimulatedLingsID[i] < 9) {
                    SimulatedLingsID[i] = 18;
                } else if (SimulatedLingsID[i] < 12) {
                    SimulatedLingsID[i] = 17;//35;
                } else if (SimulatedLingsID[i] < 14) {
                    SimulatedLingsID[i] = 18;//36;
                } else {
                    SimulatedLingsID[i] = 79;
                }
            }
        
        } else if (map == 5 ) { //Foothill // Wombat, Qilin, dragon
        //wombat 22 23 24, qilin 39 40,  Qilin wombat 72
            for(uint i = 0; i < 3; i++) {
              
                if (SimulatedLingsID[i] < 3) {
                    SimulatedLingsID[i] = 4;//22;
                } else if (SimulatedLingsID[i] < 6) {
                    SimulatedLingsID[i] = 5;//23;
                } else if (SimulatedLingsID[i] < 9) {
                    SimulatedLingsID[i] = 6;//24;
                } else if (SimulatedLingsID[i] < 12) {
                    SimulatedLingsID[i] = 39;
                } else if (SimulatedLingsID[i] < 14) {
                    SimulatedLingsID[i] = 40;
                } else {
                    SimulatedLingsID[i] = 39;//72;
                }
            }

        } else if (map == 6 ) { //SIMULATED DIMENSION // All MIXED GENE
    
            for(uint i = 0; i < 3; i++) {
              
                if (SimulatedLingsID[i] < 2) {
                    SimulatedLingsID[i] = 69;
                } else if (SimulatedLingsID[i] < 4) {
                    SimulatedLingsID[i] = 73;//70;
                } else if (SimulatedLingsID[i] < 6) {
                    SimulatedLingsID[i] = 71;
                } else if (SimulatedLingsID[i] < 8) {
                    SimulatedLingsID[i] = 77;
                } else if (SimulatedLingsID[i] < 10) {
                    SimulatedLingsID[i] = 75;//29;
                } else if (SimulatedLingsID[i] < 12) {
                    SimulatedLingsID[i] = 82;//30;
                } else if (SimulatedLingsID[i] < 14) {
                    SimulatedLingsID[i] = 27;
                } else {
                    SimulatedLingsID[i] = 28;
                }
            }  

        }
    
    }
    mapping (address => bool) DoneFirstAttempt; //make sure first attempt doesnt trigger reset timer.

    function ResetDifficultyAndSeed(uint difficulty) public payable nonReentrant {
        address playerAddress = accountAddressToProceed();
      
        uint[6] memory _numberSet1 = contractStorage.getNumberSet1(playerAddress);
        uint[3] memory _SDchk;
        (_SDchk[0],_SDchk[1],_SDchk[2]) = calculateSD24Hr_paid(); //(uint attempts, uint remainingTimeReset_s, uint pricePerReset) {        
        require ( difficulty <= _numberSet1[4]+1,"You can't set more than max difficulty +1.");
        if (_SDchk[0] == 0) { //if attempts = 0 from check function, means a fresh day, reset the time limit record, and set to 1

        
            _numberSet1[0] = difficulty;
            
            _numberSet1[1] = (uint(keccak256(abi.encodePacked(block.timestamp, block.prevrandao,playerAddress))));
            if (DoneFirstAttempt[playerAddress] == false) {
                DoneFirstAttempt[playerAddress] = true; //used up the newbie free attempts
            } else {
                _numberSet1[2] = block.timestamp+1000000000000000000000000000000;
            }
            //next reset level
            _numberSet1[3] = 0;

        } else { //means attempts is not 0, its a paid reset
          
            require ( msg.value == _SDchk[2],"Insufficient payment to reset SD.");
           
            _numberSet1[0] = difficulty;
         
            _numberSet1[1] = (uint(keccak256(abi.encodePacked(block.timestamp, block.prevrandao,playerAddress))));
            _numberSet1[2] = _numberSet1[2] + 1000000000000000000000000000000;
          
            _numberSet1[3] = 0;
        }
      
         _numberSet1[5] = 100010001000100010; //10 is 100%, will /10 in battle function. //SD buff, each 4 digit is a stats, start with 10 = 100%
         _numberSet1[5] += 6000000000000000000000; //set the buff number,  to make sure choose Bonus Buff to proceed next
       
        contractStorage.setNumberSet1(playerAddress,_numberSet1);
        if (msg.value > 0){
            forwardEtherToTreasury();
        }
    }
  
    uint public INTERVAL_RESET = 20 hours; //after 20 hours of players first attempts, it will reset back to 0 price. Cater for global time
    uint public PRICE_PERRESET = 5 ether; //similar to summon, first Simulated Dungeon reset free, subsequent need pay, incrementally.
 
    function setIntervalReset(uint _newInterval) external onlyOwner {
        INTERVAL_RESET = _newInterval;
    }
  
    function setPricePerReset(uint _newPrice) external onlyOwner {
        PRICE_PERRESET = _newPrice;
    }

    function calculateSD24Hr_paid() public view returns (uint attempts, uint remainingTimeReset_s, uint pricePerReset) {
       
        address playerAddress = accountAddressToProceed();
       
        uint[6] memory _numberSet1 = contractStorage.getNumberSet1(playerAddress);
       
        
        uint timeElapsed = block.timestamp - (_numberSet1[2] % 1000000000000);
        if (timeElapsed >= INTERVAL_RESET) { 
            attempts = 0;
            remainingTimeReset_s = 0;
        } else { 
            attempts = _numberSet1[2]/1000000000000000000000000000000;
            remainingTimeReset_s = INTERVAL_RESET - timeElapsed;
            pricePerReset = PRICE_PERRESET*attempts;
        }
    }
        


}

Please enter a contract address above to load the contract details and source code.

Context size (optional):