package space.animefu.starfallhaven;

import org.junit.Test;
import static org.junit.Assert.*;

public class ResonanceBondTest {
    @Test public void nearbyCooperativeWorkChargesBondButSoloWorkDoesNot() {
        GameWorld w=new GameWorld(5);
        GameWorld.Colonist a=w.colonists.get(0),b=w.colonists.get(1),c=w.colonists.get(2);
        a.x=10.5f;a.y=10.5f;a.tx=10;a.ty=10;
        b.x=11.0f;b.y=10.5f;b.tx=11;b.ty=10;
        c.x=30;c.y=20;c.tx=30;c.ty=20;
        w.tiles[10][10]=GameWorld.Tile.TREE;w.tiles[11][10]=GameWorld.Tile.ROCK;w.tiles[30][20]=GameWorld.Tile.TREE;
        float before=w.bondCharge;
        for(int i=0;i<10;i++)w.update(.1f);
        assertTrue("cooperative nearby work should charge bond",w.bondCharge>before);

        GameWorld solo=new GameWorld(6);
        GameWorld.Colonist only=solo.colonists.get(0);only.x=10.5f;only.y=10.5f;only.tx=10;only.ty=10;
        solo.tiles[10][10]=GameWorld.Tile.ROCK;
        solo.colonists.get(1).x=30;solo.colonists.get(1).y=20;
        solo.colonists.get(2).x=35;solo.colonists.get(2).y=22;
        for(int i=0;i<10;i++)solo.update(.1f);
        assertEquals(0,solo.bondCharge,0.001f);
    }

    @Test public void activationRequiresFullChargeAndBuffsTeamWorkCombatAndDefense() {
        GameWorld w=new GameWorld(7);
        assertFalse(w.activateBond());
        w.setBondForTest(100,0);
        assertTrue(w.activateBond());
        assertEquals(0,w.bondCharge,0f); assertTrue(w.bondActiveSeconds>0);
        assertTrue(w.teamWorkMultiplier()>1f); assertTrue(w.teamCombatMultiplier()>1f);
        assertTrue(w.teamDamageTakenMultiplier()<1f);
        float active=w.bondActiveSeconds;w.update(.1f);assertTrue(w.bondActiveSeconds<active);
    }

    @Test public void nearbyCooperativeCombatChargesBond() {
        GameWorld w=new GameWorld(8);
        for(GameWorld.Colonist c:w.colonists){c.x=10.5f;c.y=10.5f;}
        w.enemies.add(GameWorld.enemyForTest(10.8f,10.5f,1000));
        w.update(.1f);
        assertTrue(w.bondCharge>0);
    }
}
