Exemplo n.º 1
0
    // Return value indicates whether the phase is legal / has actions
    public bool executeActionsByPhase(int phaseIndex)
    {
        if (phaseIndex < 0 || phaseIndex >= maxPhaseCount)
        {
            return(false);
        }

        var actionContainer = this.containersInPhases [phaseIndex];

        if (actionContainer.isEmpty())
        {
            return(false);
        }
        // Execute movements
        foreach (var movementNode in actionContainer.movementList)
        {
            var            caster            = movementNode.caster;
            Movement       movement          = movementNode.action as Movement;
            HexCoordinates targetCoordinates = movementNode.targetCoordinates;
            movement.moveToCoordinates(caster, caster.grid, targetCoordinates.X, targetCoordinates.Y);
        }

        // Execute interactive skills
        foreach (var interactiveSkillNode in actionContainer.interactiveSkillList)
        {
            var caster                         = interactiveSkillNode.caster;
            InteractiveSkill skill             = interactiveSkillNode.action as InteractiveSkill;
            HexCoordinates   targetCoordinates = interactiveSkillNode.targetCoordinates;
            skill.settleDamageEffect(caster, caster.grid, targetCoordinates);
        }
        actionContainer.clearContainer();          // Release registration
        return(true);
    }
Exemplo n.º 2
0
        public bool UseInteractiveObject(InteractiveSkill skill)
        {
            m_useAfterMove = null;

            if (!Map.Interactives.Contains(skill.Interactive) || !skill.IsEnabled())
            {
                return(false);
            }

            if (skill.Interactive.Cell != null && !skill.Interactive.Cell.IsAdjacentTo(Cell))
            {
                var cell = skill.Interactive.Cell.GetAdjacentCells(x => Map.CanStopOnCell(x)).
                           OrderBy(x => x.ManhattanDistanceTo(Cell)).FirstOrDefault();

                if (cell == null)
                {
                    return(false);
                }

                if (Move(cell))
                {
                    m_useAfterMove = skill;
                    return(true);
                }
            }
            else
            {
                Bot.SendToServer(new InteractiveUseRequestMessage(skill.Interactive.Id, skill.Id));
                return(true);
            }

            return(false);
        }
Exemplo n.º 3
0
        public override void NotifyStopMoving(bool canceled, bool refused)
        {
            base.NotifyStopMoving(canceled, refused);

            if (m_useAfterMove != null)
            {
                if (!canceled)
                {
                    var skill = m_useAfterMove;
                    Bot.AddMessage(() => UseInteractiveObject(skill)); // call next tick
                }

                m_useAfterMove = null;
            }
            if (_actionAfterMove != null)
            {
                Bot.AddMessage(_actionAfterMove);
                _actionAfterMove = null;
            }

            if (m_nextMap != null)
            {
                if (!canceled && !refused)
                {
                    var id = m_nextMap.Value;
                    m_previousMap = Map.Id;
                    Bot.AddMessage(() => Bot.SendToServer(new ChangeMapMessage(id)));
                }

                m_nextMap = null;
            }
        }
Exemplo n.º 4
0
        public virtual void NotifyUseInteractive(InteractiveObject interactive, InteractiveSkill skill, int duration)
        {
            if (duration > 0)
            {
                UsingInteractive = interactive;
                UsingSkill       = skill;
                UsageEndTime     = DateTime.Now + TimeSpan.FromMilliseconds(duration);
            }

            UseInteractiveHandler handler = StartUsingInteractive;

            if (handler != null)
            {
                handler(this, interactive, skill, UsageEndTime);
            }
        }
Exemplo n.º 5
0
    // Events

    // Choose character or confirm actions
    void OnCellSelectedAvatar(object sender, HexGrid.CellEventArgs e)
    {
        if (!this.moveable)
        {
            return;
        }
        HexCell targetCell = e.cell;

        if (targetCell.coordinates.Equals(this.coordinates))            // The character is right on the cell
        {
            if (targetCell.state == HexCell.CellState.StateSelected)    // Cell is selected, change to state of being selected
            {
                this.isSelected = true;
                CharacterSelected(this, EventArgs.Empty);
                // Disable other cells
                this.grid.disableCellsWithOwner();
                targetCell.enableCell();
            }
            else                 // Cell is unselected, cancel state of being selected
            {
                this.isSelected      = false;
                this.isReadyToMove   = false;
                this.isReadyToAttack = false;
                this.grid.hideRangeFromSelectedCell(this.movingRangeWidth);                  // Unshow ranges
                this.grid.enableCellsWithMoveableOwner();
                targetCell.enableCell();
            }
        }
        else if (this.isSelected)            // Character not on this cell but is selected (Confirm action of move or attack)
        {
            this.originalCharacter.actionPoint -= this.currentAction.actionPoint;
            if (this.isReadyToMove)               // Character is ready to move here
            {
                Movement actionMove = this.currentAction as Movement;
                this.actionExecutor.registerAction(this.actionTakenCount++, this.originalCharacter,
                                                   actionMove, targetCell.coordinates); // Register action in action calculator
                actionMove.moveToCoordinates(this, this.grid,
                                             targetCell.coordinates.X, targetCell.coordinates.Y);
                targetCell.enableCell();
                this.grid.hideRangeFromSelectedCell(actionMove.actionDistance);                  // Unshow ranges
                this.isReadyToMove = false;
                this.isSelected    = false;
            }
            if (this.isReadyToAttack)               // Character is ready to attack here
            {
                InteractiveSkill actionSkill = this.currentAction as InteractiveSkill;
                this.actionExecutor.registerAction(this.actionTakenCount++, this, actionSkill,
                                                   targetCell.coordinates);
                this.grid.recoverRangeState(actionSkill.effectWidth, targetCell.coordinates);
                this.grid.hideRangeFromSelectedCell(actionSkill.actionDistance);                  // Unshow ranges
                this.isReadyToAttack = false;
                this.isSelected      = false;
                this.getCurrentCell().changeState(HexCell.CellState.StateDefault);
            }
            targetCell.changeState(HexCell.CellState.StateDefault);

            if (this.originalCharacter.actionPoint <= 0)               // Character no longer able to move
            {
                this.moveable = false;
                this.originalCharacter.moveable = false;
                this.isSelected = false;
                getCurrentCell().disableCell();
                this.actionTakenCount = 0;
                // Codes below should be modified or deleted if game is online
                this.grid.enableCellsWithMoveableOwner();
            }
        }
    }
Exemplo n.º 6
0
 private void OnStopUsingInteractive(RolePlayActor actor, InteractiveObject interactive, InteractiveSkill skill)
 {
     CheckRessources();
 }
Exemplo n.º 7
0
 private void OnStartUsingInteractive(RolePlayActor actor, InteractiveObject interactive, InteractiveSkill skill, DateTime?usageEndTime)
 {
     DisposeTimer();
 }