Exemplo n.º 1
0
    public override IEnumerator IEResolve()
    {
        Debug.Log("Starting Flight's IEResolve");
        running = true;
        ActionReq  a    = actions[0];
        GameGrid2D gg   = a.t == pb.pobj.playerId ? pb.playerGrid : pb.enemyGrid;                                                      // Select grid to get coord's
        Cell2D     cell = gg.GetCell(a.loc[0]);
        CellStruct cs   = a.t == pb.pobj.playerId ? pGrid[(int)a.loc[0].x, (int)a.loc[0].y] : eGrid[(int)a.loc[0].x, (int)a.loc[0].y]; //TODO change this garbage
        float      time = 0;

        while (time <= delay) //Delay first
        {
            time += Time.deltaTime;
            yield return(null);
        }
        time = 0; //Delay artificially for a bit;
        cell.OnBuild();
        cell.SetCellStruct(cs);
        while (time <= buildDelay)
        {
            time += Time.deltaTime;
            yield return(null);
        }
        running = false;
        Destroy(gameObject);
    }
Exemplo n.º 2
0
 bool DefShotCB(ActionReq ar)
 {
     //Debug.Log("CB handler: DefShotCB loc " + this.loc.ToString());
     //Always check if we're a mine first, must punish
     if (ar.a == pAction.blockingShot)
     {
         if (this.bldg == CBldg.empty)
         {
             this.ChangeCellBldg(CBldg.blocker);
         }
         else
         {
             Debug.LogError("Trying to block a non empty cell! " + ar.ToString());
         }
     }
     else if (ar.a == pAction.towerTakeover)
     {
         if (new List <CBldg> {
             CBldg.towerOffence, CBldg.towerDefence, CBldg.towerIntel
         }.Contains(this.bldg))
         {
             this.defected = true;
         }
         this.vis = true;                 // Should we destroy otherwise?
     }
     else
     {
         this.DestroyCell(true);
     }
     return(true);
 }
Exemplo n.º 3
0
        public List <ActionReq> GetLastActions(int player)
        {
            List <ActionReq> retList = new List <ActionReq>();

            foreach (ActionReq ar in this.lastActions)
            {
                if (ar.p == player)                 // If the player owns the action, add it regardless
                {
                    retList.Add(ar);
                    continue;
                }
                ReportType rt = PlayerActionTracker.actionParams[ar.a].reportType;
                switch (rt)
                {
                case ReportType.Hidden:                 // Do nothing here, don't add to list
                    break;

                case ReportType.NameOnly:
                    ActionReq newar = new ActionReq(ar.p, ar.t, ar.a, null);
                    retList.Add(newar);
                    break;

                case ReportType.Visible:
                    retList.Add(ar);
                    break;

                default:
                    Debug.LogErrorFormat("GetLastActions(): Error, unhandled report type: {0}", rt);
                    break;
                }
            }
            return(retList);
        }
Exemplo n.º 4
0
    //////////////////////////////
    // Library of validators
    bool TargetsSelf(ActionReq ar)
    {
        bool resl = ar.t == ar.p;

        //Debug.Log("TargetsSelf returning: " + resl);
        return(resl);
    }
Exemplo n.º 5
0
    bool LocCountEq(ActionReq ar, int count)
    {
        bool resl = ar.loc.Length == count;

        //Debug.Log("LocCountEq returning: " + resl);
        return(resl);
    }
Exemplo n.º 6
0
    //////////////////////////
    //Main validators
    bool DefBuildValid(ActionReq ar, CellStruct[,] pGrid, Vector2 gridSize)
    {
        //Checks: targets player grid, has only one listed coord
        bool resl = TargetsSelf(ar) && LocCountEq(ar, 1) && BldgIs(pGrid, ar.loc[0], CBldg.empty) && !Destroyed(pGrid, ar.loc[0]);

        //Debug.Log("DefBuildValid returning " + resl.ToString());
        return(resl);
    }
Exemplo n.º 7
0
    bool ScoutValid(ActionReq ar, CellStruct[,] eGrid, Vector2 gridSize)
    {
        //Checks: target enemy, has only 1 loc, target is hidden
        bool resl = !TargetsSelf(ar) && LocCountEq(ar, 1) && BldgIs(eGrid, ar.loc[0], CBldg.hidden);

        //Debug.Log("ScoutValid returned " + resl.ToString());
        return(resl);
    }
Exemplo n.º 8
0
    bool FireValid(ActionReq ar, Vector2 gridSize)
    {
        //Checks that player not targeting self,  only one loc specified, target is in our grid
        bool resl = !TargetsSelf(ar) && LocCountEq(ar, 1) && LocInGrid(ar.loc[0], gridSize);

        //Debug.Log("Attack Valid returned " + resl.ToString());
        return(resl);
    }
Exemplo n.º 9
0
        bool DefScoutedCB(ActionReq ar)
        {
            const int maxDuration = 4;

            Debug.Log("Handling getting scouted at loc " + this.loc.ToString());
            this.scouted       = true;
            this.scoutDuration = maxDuration;
            return(true);
        }
Exemplo n.º 10
0
 bool MineShotCB(ActionReq ar)
 {
     if (!this.destroyed)
     {
         this.pb.SetActionCooldown(ar.p, pAction.fireBasic, 3);
     }
     this.DestroyCell(true);
     return(true);
 }
Exemplo n.º 11
0
 /////////////Callbacks
 bool WallCB(ActionReq ar)
 {
     //Debug.Log("CB handler: WallCB loc" + this.loc.ToString());
     if (ar.a == pAction.towerTakeover)             //Actions that don't trigger walls can be added here
     {
         return(false);
     }
     this.DestroyCell(true);
     return(ar.a != pAction.firePiercing);
 }
Exemplo n.º 12
0
    ///////////////////////////
    //Validate builds during multiTower phase
    bool MultiTowerValid(ActionReq ar, CellStruct[,] pGrid, Vector2 gridSize)
    {
        Dictionary <pAction, CBldg> mapping = new Dictionary <pAction, CBldg> {
            { pAction.buildOffenceTower, CBldg.towerOffence },
            { pAction.buildDefenceTower, CBldg.towerDefence },
            { pAction.buildIntelTower, CBldg.towerIntel }
        };

        return(!GridContainsBldg(pGrid, mapping[ar.a]) && DefBuildValid(ar, pGrid, gridSize) && !NextToBldgs(pGrid, ar.loc[0], mapping.Values.ToList(), gridSize));
    }
Exemplo n.º 13
0
 public void UpdateShoottxt(ActionReq newAR)
 {
     if (newAR.a == pAction.noAction)
     {
         this.Clear();
     }
     else
     {
         this.shoottxt.text = "Shoot: " + newAR.a.ToString() + " at " + newAR.loc[0].ToString();
     }
 }
Exemplo n.º 14
0
    public void RXGridHover(bool pGrid, Vector2 pos, bool enter)
    {
        if (!enter)         // On hover Exit, just clear the hover states
        {
            ClearSelectionState(true);
            return;
        }
        int       target = pGrid ? 0 : 1;   // This is janky, but we want the target to match sender if on player's grid
        ActionReq ar     = new ActionReq(0, target, actionContext, new Vector2[] { pos });

        HoverAction(ar);
    }
Exemplo n.º 15
0
 public void UpdateActiontxt(ActionReq newAR)
 {
     if (newAR.a == pAction.noAction)
     {
         this.Clear();
     }
     else
     {
         string locstr = newAR.loc.Length > 0 ? newAR.loc[0].ToString() : "null";
         this.actiontxt.text = "Action: " + newAR.a.ToString() + " at " + locstr;
     }
 }
Exemplo n.º 16
0
    bool BuildTowerValid(ActionReq ar, CellStruct[,] pGrid, Vector2 gridSize, List <Vector2> capLocs)
    {
        //Does the more complicated checking for valid tower placement
        List <CBldg> bldgs = new List <CBldg> {
            CBldg.towerOffence, CBldg.towerIntel, CBldg.towerDefence
        };
        bool resl = DefBuildValid(ar, pGrid, gridSize) && AdjacentToCountBldgs(pGrid, ar.loc[0], bldgs, gridSize, 1) && TowerPlacementOnEnd(pGrid, ar.loc[0], new List <Vector2>(), gridSize) &&
                    CheckChainAlive(pGrid, ar.loc[0], gridSize, capLocs) && CheckChainLengthValid(pGrid, ar.loc[0], gridSize, capLocs);

        //Debug.Log("BuildTowerValid returning " + resl.ToString());
        GetTowerChainsSunk(pGrid, gridSize, capLocs);
        return(resl);
    }
Exemplo n.º 17
0
    void SetCellAction(ActionReq ar, bool hover)
    {
        GameGrid2D g = ar.p == ar.t ? this.playerGrid : this.enemyGrid;

        if (ar.loc == null)
        {
            return;             // Return early if there's not loc of cell given. Nothing will be done
        }
        switch (ar.a)
        {
        case pAction.fireBasic:
        case pAction.fireAgain:
        case pAction.buildWall:
        case pAction.buildOffenceTower:
        case pAction.buildDefenceTower:
        case pAction.buildIntelTower:
        case pAction.scout:
        case pAction.placeMine:
        case pAction.buildReflector:
        case pAction.firePiercing:
        case pAction.noAction:
        case pAction.towerTakeover:
            g.SetSingleSelect(hover, ar.loc[0]);
            break;

        case pAction.fireRow:
            g.SetRowSelect(hover, (int)ar.loc[0].y);
            break;

        case pAction.fireSquare:
            g.SetEmptySquareSelect(hover, ar.loc[0]);
            break;

        case pAction.placeMole:
            g.SetSquare3Select(hover, ar.loc[0], 1);             // 3x3 square
            break;

        case pAction.buildDefenceGrid:
            g.SetSquare3Select(hover, ar.loc[0], 2);             // 5x5 square
            break;

        case pAction.blockingShot:         // these guys don't have any targeting or loc in their action
        case pAction.hellFire:
        case pAction.flare:
            break;

        default:
            Debug.Log("Unhandled pAction Type: " + ar.a.ToString());
            break;
        }
    }
Exemplo n.º 18
0
        void ExecPriorityList(List <PriorityCB> pcbl, PriorityCB def, ActionReq ar)
        {
            //Debug.Log("Cell: Executing priorty list. " + pcbl.Count().ToString());
            List <PriorityCB> list = new List <PriorityCB>();

            list.AddRange(pcbl);       // Add special callbacks
            list.Add(def);             // Add default callback
            list.OrderByDescending(cb => cb.p).ToList();
            foreach (PriorityCB pcb in list)
            {
                if (pcb.f(ar))
                {
                    break;
                }
            }
        }
Exemplo n.º 19
0
 bool ReflectorShotCB(ActionReq ar)
 {
     if (ar.a == pAction.fireReflected)             // so there's no looping, just blow this up if we're hit with a reflected shot
     {
         this.DestroyCell(true);
     }
     else
     {
         this.vis       = true;
         this.reflected = true;                 // mark as reflected so that UI can display the difference to owner
         Vector2 loc = new Vector2(Random.Range(0, this.pb.sizex - 1), Random.Range(0, this.pb.sizey - 1));
         //Debug.Log("Ping! Deflected that shot : " + this.reflected.ToString());
         pb.CellApplyActionReqs(new List <ActionReq> {
             new ActionReq(ar.t, ar.p, pAction.fireReflected, new Vector2[] { loc })
         });
     }
     return(true);
 }
Exemplo n.º 20
0
    public override void Init(List <ActionReq> actions, PlayBoard2D pb, CellStruct[,] pGrid, CellStruct[,] eGrid)
    {
        base.argInit(actions, pb, pGrid, eGrid);
        projectile     = GetComponent <SpriteRenderer>();
        orig_z         = transform.position.z;
        orig_scale     = transform.localScale;
        hitParticle    = transform.Find("HitParticle").GetComponent <ParticleSystem>();
        trailParticle  = GetComponent <ParticleSystem>();
        rock           = transform.Find("Rock").gameObject;
        rockSpriteRend = rock.GetComponent <SpriteRenderer>();
        ActionReq  a    = actions[0];
        GameGrid2D gg   = a.t == pb.pobj.playerId ? pb.playerGrid : pb.enemyGrid; // Select grid to get coord's
        Cell2D     cell = gg.GetCell(a.loc[0]);

        this.startpos           = a.p == pb.pobj.playerId ? pb.playerShotOrig : pb.enemyShotOrig;
        this.transform.position = startpos;
        this.endpos             = cell.transform.position;
    }
Exemplo n.º 21
0
    public override IEnumerator IEResolve()
    {
        running = true;
        Debug.Log("Starting Flight's IEResolve");
        float time = 0;

        //Delay first
        while (time <= delay)
        {
            time += Time.deltaTime;
            yield return(null);
        }
        time = 0; // Now launch
        trailParticle.Play(false);
        while (time <= duration)
        {
            float interpolant = time / duration;
            //Set new scale
            float   scale    = Mathf.Lerp(scaleMin, scaleMax, curve.Evaluate(interpolant));
            Vector3 newscale = new Vector3(orig_scale.x * scale, orig_scale.y * scale, orig_scale.z); // Scale object up and down based on curve, multipled by height scalar
            transform.localScale = newscale;
            //Set new position
            Vector3 newpos = Vector3.Lerp(startpos, endpos, interpolant);
            newpos.z           = orig_z;
            transform.position = newpos;
            //Update rotation
            rock.transform.Rotate(new Vector3(0, 0, rotation * Time.deltaTime));
            //Update time and yield
            time += Time.deltaTime;
            yield return(null);
        }
        Debug.Log("Projectile has landed");
        //the projectile has landed, play sound, update cell, etc.
        ActionReq  a    = actions[0];
        GameGrid2D gg   = a.t == pb.pobj.playerId ? pb.playerGrid : pb.enemyGrid;                                                      // Select grid to get coord's
        Cell2D     cell = gg.GetCell(a.loc[0]);
        CellStruct cs   = a.t == pb.pobj.playerId ? pGrid[(int)a.loc[0].x, (int)a.loc[0].y] : eGrid[(int)a.loc[0].x, (int)a.loc[0].y]; //TODO change this garbage

        cell.OnHit();
        cell.SetCellStruct(cs);
        running = false; // Say we're done running when we hit the end location
        StartCoroutine(IEFade());
    }
Exemplo n.º 22
0
        bool DefBuiltCB(ActionReq ar)
        {
            //Debug.Log("CB handler: DefBuiltCB loc " + this.loc.ToString());
            switch (ar.a)
            {
            case pAction.buildOffenceTower:
                this.ChangeCellBldg(CBldg.towerOffence);
                break;

            case pAction.buildDefenceTower:
                this.ChangeCellBldg(CBldg.towerDefence);
                break;

            case pAction.buildIntelTower:
                this.ChangeCellBldg(CBldg.towerIntel);
                break;

            case pAction.buildWall:
                this.ChangeCellBldg(CBldg.wall);
                break;

            case pAction.placeMine:
                this.ChangeCellBldg(CBldg.mine);
                break;

            case pAction.buildDefenceGrid:
                this.ChangeCellBldg(CBldg.defenceGrid);
                break;

            case pAction.buildReflector:
                this.ChangeCellBldg(CBldg.reflector);
                break;

            case pAction.placeMole:
                this.mole = true;
                break;

            default:
                Debug.LogError("EmptyBuildCB: Default case unhandled. " + ar.a.ToString());
                return(false);
            }
            return(true);
        }
Exemplo n.º 23
0
    //Buttons should either call this so we know what we're supposed to do when clicking on the grid or...
    public void SetActionContext(pAction action)
    {
        List <pAction> noTarget = new List <pAction> {
            pAction.hellFire, pAction.blockingShot, pAction.flare
        };

        this.actionContext      = action;
        this.pb2d.actionContext = this.actionContext;
        UIController.instance.ActionSelectButtonGrpHighlight(action);
        if (noTarget.Contains(action))         //No target for this action, just set it and move on with your life
        {
            switch (this.apc)
            {
            case ActionProcState.reject:
            case ActionProcState.multiTower:
                Debug.Log("APC Reject: Ignoring input from SetTargetlessAction");
                break;

            case ActionProcState.basicActions:
                Debug.Log("Setting single action: " + action.ToString());
                //Right now, all non targeted actions hit enemy, may need to change in the future
                ActionReq newAR = new ActionReq(this.report.playerId, this.report.enemyId, action, new Vector2[0]);
                if (this.v.Validate(newAR, this.report.latestPlayerGrid, this.report.latestEnemyGrid, new Vector2(pb2d.sizex, pb2d.sizey), this.report.latestCapitolLocs))                 //TODO do we really need to validate here?
                {
                    Debug.Log("Validated action: " + newAR.ToString());
                    this.queuedActions[1] = newAR;
                    this.pb2d.SetActions(this.queuedActions);                     //clear old action selection
                    UIController.instance.ActionDisplayUpdateAction(newAR);
                }
                else
                {
                    Debug.Log("Bad action: " + newAR.ToString());
                }
                break;

            default:
                Debug.LogError("SetActionContext unhandled actionprocstate: " + this.apc.ToString());
                break;
            }
        }
    }
Exemplo n.º 24
0
        bool DefenceGridCB(ActionReq ar)
        {
            if (ar.a == pAction.towerTakeover)             //Actions that don't trigger defence grids can be added here
            {
                return(false);
            }
            const int maxHits = 3;

            //Todo, we need a way to show this to the player!
            this.pb.CellSetDefGridBlock(ar.t, new Vector2Int((int)ar.loc[0].x, (int)ar.loc[0].y), true);             // show the player that they were blocked
            if (!this.defenceGridActive)
            {
                this.defenceGridHits++;
                this.defenceGridActive = true;
            }
            Debug.LogWarning("CB handler: DefenceGridCB blocked shot #" + this.defenceGridHits.ToString() + " at loc" + this.loc.ToString());
            if (this.defenceGridHits >= maxHits)
            {
                this.DestroyCell(true);
            }
            return(true);
        }
Exemplo n.º 25
0
 //#############################################
 //Functions to control our Action Display
 //UpdateAction
 public void ActionDisplayUpdateAction(ActionReq ar)
 {
     this.ad.UpdateActiontxt(ar);
 }
Exemplo n.º 26
0
 public void HoverAction(ActionReq inputAction)
 {
     ClearSelectionState(true);
     SetCellAction(inputAction, true);
 }
Exemplo n.º 27
0
 public void onScout(ActionReq ar)
 {
     //Debug.Log("Cell: " + this.loc.ToString() + " onScout");
     this.ExecPriorityList(this.scoutCBs, this.scoutDef, ar);
 }
Exemplo n.º 28
0
 //TODO does this need to be unique for shot,built,scouted?
 bool NullCB(ActionReq ar)
 {
     //Debug.Log("CB handler: NullCB loc " + this.loc.ToString() + ". Do nothing. Bldg: " + this.bldg.ToString());
     return(true);
 }
Exemplo n.º 29
0
    public void RXInput(bool pGrid, Vector2 pos, CellStruct cs)
    {
        //Don't need to ensure local player, grid only assigned to localplayer
        if (this.actionLocked)
        {
            //Debug.Log("Got input, but we're already locked... ignoring");
            return;
        }
        switch (this.apc)
        {
        case ActionProcState.reject:
            Debug.Log("APC Reject: Ignoring input from grid");
            //Do nothing, we ignore the request
            break;

        case ActionProcState.multiTower:
            if (!pGrid)              // Only build on our side
            {
                break;               // Our validator would catch this, but we do some more logic below that relies on this assumption
            }
            int idx;
            Dictionary <pAction, CellStruct> buildDict = new Dictionary <pAction, CellStruct> {
                { pAction.buildOffenceTower, new CellStruct(CBldg.towerOffence) },
                { pAction.buildDefenceTower, new CellStruct(CBldg.towerDefence) },
                { pAction.buildIntelTower, new CellStruct(CBldg.towerIntel) }
            };
            CellStruct[][,] currentGrids = this.pb2d.GetGridStates();
            ActionReq MultiTowerAR = new ActionReq(this.report.playerId, this.report.playerId, this.actionContext, new Vector2[] { pos });
            if (this.v.Validate(MultiTowerAR, currentGrids[0], currentGrids[1], pb2d.GetGridVec2Size(), this.report.latestCapitolLocs))
            {
                idx = this.queuedActions.FindIndex(x => x.a == pAction.noAction);
                if (idx >= 0)
                {
                    Debug.Log("Input processor: Valid Move: Add new AR at " + idx.ToString() + ", ar: " + MultiTowerAR.ToString());
                    this.queuedActions[idx] = MultiTowerAR;
                    this.pb2d.SetCellStruct(true, pos, buildDict[this.actionContext]);
                    break;
                }
            }
            else
            {
                Debug.LogFormat("Input processor: Invalid request, don't add to list: {0}", MultiTowerAR.ToString());
            }
            if (this.v.BldgIn(currentGrids[0], pos, buildDict.Values.ToList().Select(cstruct => cstruct.bldg).ToList()))              // Now, if there is a tower here already, remove it
            {
                idx = this.queuedActions.FindIndex(x => buildDict.Keys.ToList().Contains(x.a) && x.loc != null && x.loc[0] == pos);
                if (idx >= 0)
                {
                    Debug.Log("Input processor: Removing AR that is in this place");
                    this.queuedActions[idx] = new ActionReq(this.report.playerId, this.report.playerId, pAction.noAction, null);
                    this.pb2d.SetCellStruct(true, pos, new CellStruct(CBldg.empty));
                }
            }
            break;

        case ActionProcState.basicActions:
            ActionReq singleAR = new ActionReq(this.report.playerId, this.report.playerId, pAction.noAction, null); // NoAction should always fail eval
            int       target   = pGrid ? this.report.playerId : this.report.enemyId;
            switch (this.actionContext)                                                                             // May not need this to be a switch statement after refactor... lol TODO
            {
            case pAction.noAction:
                break;                 // don't do nuthin if no action context

            case pAction.blockingShot: //These guys don't need a target, don't do anything here, assume handled by set action context
            case pAction.hellFire:
            case pAction.flare:
                break;

            case pAction.fireBasic:         // All of these single targeted actions can be handled the same way
            case pAction.scout:             // All differences in placement rules are handled by the validator
            case pAction.buildDefenceTower:
            case pAction.buildOffenceTower:
            case pAction.buildIntelTower:
            case pAction.buildWall:
            case pAction.fireAgain:
            case pAction.fireRow:             // this is multi location, but still single targeted shot
            case pAction.fireSquare:          // this is multi location, but still single targeted shot
            case pAction.placeMine:
            case pAction.buildDefenceGrid:
            case pAction.buildReflector:
            case pAction.firePiercing:
            case pAction.placeMole:
            case pAction.towerTakeover:
                singleAR = new ActionReq(this.report.playerId, target, this.actionContext, new Vector2[] { pos });
                break;

            case pAction.fireReflected:
                Debug.LogError("Player input should never be able to make this action! " + this.actionContext.ToString());
                break;

            default:
                Debug.LogError("Input processor unhandled actionContext: " + this.actionContext.ToString());
                break;
            }
            if (this.v.Validate(singleAR, this.report.latestPlayerGrid, this.report.latestEnemyGrid, pb2d.GetGridVec2Size(), this.report.latestCapitolLocs))
            {
                Debug.Log("Validated action: " + singleAR.ToString());
                if (singleAR.a == pAction.fireBasic)
                {
                    this.queuedActions[0] = singleAR;
                }
                else
                {
                    this.queuedActions[1] = singleAR;
                }
                this.pb2d.SetActions(this.queuedActions);                 //add new action select
                UIController.instance.ActionDisplayUpdateShoot(singleAR);
            }
            else
            {
                Debug.Log("Bad action: " + singleAR.ToString());
            }
            break;

        default:
            Debug.LogError("Input processor unhandled actionprocstate: " + this.apc.ToString());
            break;
        }
    }
Exemplo n.º 30
0
 //UpdateShoot
 public void ActionDisplayUpdateShoot(ActionReq ar)
 {
     this.ad.UpdateShoottxt(ar);
 }