Esempio n. 1
0
        void Handle_ActionsPopoverItemClicked(object sender, ButtonStringPopover.PopoverEventArgs e)
        {
            CharacterActionItem item = (CharacterActionItem)e.Tag;

            if (item.Action != CharacterActionType.None)
            {
                CharacterActionResult res = CharacterActions.TakeAction(_CombatState, item.Action, _Character, new List <Character>()
                {
                    _Character
                }, item.Tag);
                switch (res)
                {
                case CharacterActionResult.NeedConditionDialog:

                    _ConditionView = new ConditionViewController();
                    _ConditionView.ConditionApplied += ConditionApplied;
                    MainUI.MainView.AddSubview(_ConditionView.View);
                    break;

                case CharacterActionResult.NeedNotesDialog:

                    _TextBoxDialog            = new TextBoxDialog();
                    _TextBoxDialog.HeaderText = "Notes";
                    _TextBoxDialog.Value      = _Character.Notes;
                    MainUI.MainView.AddSubview(_TextBoxDialog.View);
                    _TextBoxDialog.OKClicked += Handle_NotesTextBoxDialogOKClicked;
                    break;

                case CharacterActionResult.NeedMonsterEditorDialog:
                    Monster newMonster = (Monster)Character.Monster.Clone();

                    _MonsterEditorDialog = new MonsterEditorDialog(newMonster);
                    _MonsterEditorDialog.MonsterEditorComplete += (sd, monster) =>
                    {
                        Character.Monster.CopyFrom(newMonster);
                    };
                    MainUI.MainView.AddSubview(_MonsterEditorDialog.View);

                    break;

                case CharacterActionResult.RollAttack:
                    DieRollerView.Roller.RollAttack((Attack)item.Tag, _Character);
                    break;

                case CharacterActionResult.RollAttackSet:
                    DieRollerView.Roller.RollAttackSet((AttackSet)item.Tag, _Character);
                    break;

                case CharacterActionResult.RollSave:
                    DieRollerView.Roller.RollSave((Monster.SaveType)item.Tag, _Character);
                    break;

                case CharacterActionResult.RollSkill:
                    var sks = (Tuple <string, string>)item.Tag;
                    DieRollerView.Roller.RollSkill(sks.Item1, sks.Item2, _Character);
                    break;
                }
            }
        }
Esempio n. 2
0
        void ListViewItemClick(object sender, AdapterView.ItemClickEventArgs e)
        {
            ListView lv = (ListView)FindViewById(Resource.Id.actionListView);
            CharacterActionsAdapter ca = (CharacterActionsAdapter)lv.Adapter;
            CharacterActionItem     ai = ca.ActionItems[e.Position];

            if (ai.SubItems != null)
            {
                ca.MoveToSubItems(ai);
                ca.NotifyDataSetChanged();
            }
            else if (ai.Name != null && ai.Name.Length > 0)
            {
                CharacterActionResult res = CharacterActions.TakeAction(_State, ai.Action, _Character, new List <CombatManager.Character>()
                {
                    _Character
                }, ai.Tag);
                Dismiss();

                switch (res)
                {
                case CharacterActionResult.NeedAttacksDialog:
                    break;

                case CharacterActionResult.NeedMonsterEditorDialog:
                    ShowMonsterEditor();
                    break;

                case CharacterActionResult.NeedConditionDialog:
                    ShowConditionDialog();
                    break;

                case CharacterActionResult.NeedNotesDialog:
                    ShowNotesDialog();
                    break;

                case CharacterActionResult.RollAttack:
                    _State.Roll(CombatState.RollType.Attack, _Character, (Attack)ai.Tag, null);
                    break;

                case CharacterActionResult.RollAttackSet:
                    _State.Roll(CombatState.RollType.AttackSet, _Character, (AttackSet)ai.Tag, null);
                    break;

                case CharacterActionResult.RollSave:

                    _State.Roll(CombatState.RollType.Save, _Character, (Monster.SaveType)ai.Tag, null);
                    break;

                case CharacterActionResult.RollSkill:
                    var sks = (Tuple <string, string>)ai.Tag;
                    _State.Roll(CombatState.RollType.Skill, _Character, sks.Item1, sks.Item2);
                    break;
                }
            }
        }
    /// <summary>
    /// Execute action
    /// </summary>
    public override CharacterActionResult Execute(float deltaTime)
    {
        CharacterActionResult result = new CharacterActionResult();

        result.velocity  = Controller2D.BaseVelocity;
        _hit.FoundAnyHit = false;

        _verifyCollision = false;

        if (_moveAxis != Vector3.zero /*&& !snapToWall*/)
        {
            _direction = _moveAxis;
        }

        if (Controller2D.HitStatus.FoundAnyHit && !isExecuting)
        {
            if (((wallSlideLayers.value & 1 << Controller2D.HitStatus.HitCollider.gameObject.layer) == 1 << Controller2D.HitStatus.HitCollider.gameObject.layer))
            {
                isExecuting = true;

                if (snapToWall)
                {
                    _direction = (Controller2D.HitStatus.HitPoint - Controller2D.TransientPosition);
                }
            }
        }

        if (snapToWall || _moveAxis != Vector3.zero)
        {
            _verifyCollision = true;
        }

        if (isExecuting && _verifyCollision)
        {
            Vector2      targetMovementVelocity = Vector2.zero;
            RaycastHit2D closestSweepHit;

            if (Controller2D.CharacterCollisionsSweep(Controller2D.TransientPosition + _handPosCenterToBottom - Controller2D.CharacterTransformToCapsuleCenter, Controller2D.TransientRotation, _direction, 0.2f, out closestSweepHit, _internalCharacterHits, 0, _capHeight) > 0)
            {
                if ((!Controller2D.MustUnground))
                {
                    Controller2D.Gravity = Vector2.zero;

                    if (snapToWall)
                    {
                        _direction = (closestSweepHit.point - Controller2D.TransientPosition);
                    }

                    result.velocity = (-Controller2D.CharacterUp * fallingSpeed) + (Controller2D.CharacterRight * result.velocity.x);

                    _hit.FoundAnyHit = true;
                    _hit.HitCollider = closestSweepHit.collider;
                    _hit.HitNormal   = closestSweepHit.normal;
                    _hit.HitPoint    = closestSweepHit.point;

                    result.velocity = Vector3.ProjectOnPlane(result.velocity, _hit.HitNormal);

                    targetMovementVelocity = result.velocity;

                    // Smooth movement Velocity
                    result.velocity = Vector2.Lerp(result.velocity, targetMovementVelocity, deltaTime);

                    OnSlidingWall.Invoke(_hit);
                }
                else
                {
                    if (_moveAxis != Vector3.zero)
                    {
                        _direction = _moveAxis;
                    }
                    Controller2D.Gravity = OriginalGravity;
                }
            }
            else
            {
                ExitExecute(deltaTime);
            }
        }
        else
        {
            ExitExecute(deltaTime);
        }
        return(result);
    }
Esempio n. 4
0
        public static CharacterActionResult TakeAction(CombatState state, CharacterActionType action, Character primaryChar, List <Character> allChars, object param)
        {
            CharacterActionResult res = CharacterActionResult.None;

            switch (action)
            {
            case CharacterActionType.MakeIdle:
                foreach (Character ch in allChars)
                {
                    ch.IsIdle = true;
                }
                state.FilterList();
                break;

            case CharacterActionType.RemoveIdle:
                foreach (Character ch in allChars)
                {
                    ch.IsIdle = false;
                }
                state.FilterList();
                break;

            case CharacterActionType.Clone:
                foreach (Character ch in allChars)
                {
                    state.CloneCharacter(ch);
                }
                break;

            case CharacterActionType.Delete:
                foreach (Character ch in allChars)
                {
                    state.RemoveCharacter(ch);
                }
                break;

            case CharacterActionType.MoveToMonsters:
                foreach (Character ch in allChars)
                {
                    if (!ch.IsMonster)
                    {
                        state.RemoveCharacter(ch);
                        ch.IsMonster = true;
                        state.AddCharacter(ch);
                    }
                }
                state.FilterList();
                break;

            case CharacterActionType.MoveToParty:
                foreach (Character ch in allChars)
                {
                    if (ch.IsMonster)
                    {
                        state.RemoveCharacter(ch);
                        ch.IsMonster = false;
                        state.AddCharacter(ch);
                    }
                }
                state.FilterList();
                break;

            case CharacterActionType.MoveUpInitiative:
                state.MoveUpCharacter(primaryChar);
                break;

            case CharacterActionType.MoveDownInitiative:
                state.MoveDownCharacter(primaryChar);
                break;

            case CharacterActionType.MoveAfterInitiative:
                state.MoveCharacterAfter(primaryChar, (Character)param);
                break;

            case CharacterActionType.MoveBeforeInitiative:
                state.MoveCharacterBefore(primaryChar, (Character)param);
                break;

            case CharacterActionType.RollInitiative:
                state.RollIndividualInitiative(primaryChar);
                state.SortCombatList(false, false);
                break;

            case CharacterActionType.Ready:
                primaryChar.IsReadying = !primaryChar.IsReadying;
                if (primaryChar.IsReadying && primaryChar.IsDelaying)
                {
                    primaryChar.IsDelaying = false;
                }
                break;

            case CharacterActionType.Delay:
                primaryChar.IsDelaying = !primaryChar.IsDelaying;
                if (primaryChar.IsReadying && primaryChar.IsDelaying)
                {
                    primaryChar.IsReadying = false;
                }
                break;

            case CharacterActionType.ActNow:
                if (primaryChar.IsIdle)
                {
                    primaryChar.IsIdle = false;
                }
                state.CharacterActNow(primaryChar);
                break;

            case CharacterActionType.LinkInitiative:
                Character targetChar = (Character)param;
                if (primaryChar != targetChar && targetChar.InitiativeLeader == null)
                {
                    state.LinkInitiative(primaryChar, (Character)param);
                }
                break;

            case CharacterActionType.UnlinkInitiative:
                state.UnlinkLeader(primaryChar);
                break;

            case CharacterActionType.AddConditon:
                if (param != null)
                {
                    Condition c = (Condition)param;
                    foreach (Character ch in allChars)
                    {
                        ActiveCondition a = new ActiveCondition();
                        a.Condition = c;
                        ch.Stats.AddCondition(a);
                        Condition.PushRecentCondition(a.Condition);
                    }
                }
                else
                {
                    res = CharacterActionResult.NeedConditionDialog;
                }
                break;

            case CharacterActionType.EditNotes:
                res = CharacterActionResult.NeedNotesDialog;
                break;

            case CharacterActionType.EditMonster:
                res = CharacterActionResult.NeedMonsterEditorDialog;
                break;

            case CharacterActionType.RollAttack:
                res = CharacterActionResult.RollAttack;
                break;

            case CharacterActionType.RollAttackSet:
                res = CharacterActionResult.RollAttackSet;
                break;

            case CharacterActionType.RollSave:
                res = CharacterActionResult.RollSave;
                break;

            case CharacterActionType.RollSkill:
                res = CharacterActionResult.RollSkill;
                break;
            }
            return(res);
        }
Esempio n. 5
0
    /// <summary>
    /// Execute action
    /// </summary>
    public override CharacterActionResult Execute(float deltaTime)
    {
        Vector3 _moveInputVector = Vector3.zero;

        if (Parameters != null)
        {
            _moveInputVector = (Vector3)Parameters [0];
        }

        CharacterActionResult result = new CharacterActionResult();

        result.velocity = Controller2D.BaseVelocity;

        Vector2 targetMovementVelocity = Vector2.zero;

        if (Controller2D.GroundingStatus.IsStableOnGround)
        {
            Vector2 effectiveGroundNormal = Controller2D.GroundingStatus.GroundNormal;
            if (result.velocity.sqrMagnitude > 0f && Controller2D.GroundingStatus.SnappingPrevented)
            {
                // Take the normal from where we're coming from
                Vector2 groundPointToCharacter = Controller2D.TransientPosition - Controller2D.GroundingStatus.GroundPoint;
                if (Vector2.Dot(result.velocity, groundPointToCharacter) >= 0f)
                {
                    effectiveGroundNormal = Controller2D.GroundingStatus.OuterGroundNormal;
                }
                else
                {
                    effectiveGroundNormal = Controller2D.GroundingStatus.InnerGroundNormal;
                }
            }

            float velocityY = result.velocity.y;
            // Reorient velocity on slope
            if (Controller2D.IsSnappedToGround())
            {
                result.velocity = Controller2D.GetDirectionTangentToSurface(result.velocity, effectiveGroundNormal) * result.velocity.magnitude;
            }


            // Calculate target velocity
            Vector3 inputRight      = Vector3.Cross(_moveInputVector, Controller2D.CharacterUp);
            Vector3 reorientedInput = Vector3.Cross(effectiveGroundNormal, inputRight).normalized *_moveInputVector.magnitude;
            targetMovementVelocity   = reorientedInput * MaxStableMoveSpeed;
            targetMovementVelocity.y = velocityY;

            // Smooth movement Velocity
            result.velocity = Vector2.Lerp(result.velocity, targetMovementVelocity, StableMovementSharpness * deltaTime);
        }
        else
        {
            // Add move input
            //if (_moveInputVector.sqrMagnitude > 0f) {
            targetMovementVelocity = _moveInputVector * MaxAirMoveSpeed;

            if (_moveInputVector.sqrMagnitude > 0f)
            {
                // Prevent climbing on un-stable slopes with air movement
                if (Controller2D.GroundingStatus.FoundAnyGround)
                {
                    Vector3 perpenticularObstructionNormal = Vector3.Cross(Vector3.Cross(Controller2D.CharacterUp, Controller2D.GroundingStatus.GroundNormal), Controller2D.CharacterUp).normalized;
                    targetMovementVelocity = Vector3.ProjectOnPlane(targetMovementVelocity, perpenticularObstructionNormal);
                }
            }

            Vector3 velocityDiff = Vector3.ProjectOnPlane(targetMovementVelocity - result.velocity, Controller2D.Gravity);
            result.velocity += new Vector2(velocityDiff.x, velocityDiff.y) * AirAccelerationSpeed * deltaTime;
            //}
        }

        return(result);
    }
    /// <summary>
    /// Execute action
    /// </summary>
    public override CharacterActionResult Execute(float deltaTime)
    {
        CharacterActionResult result = new CharacterActionResult();

        result.velocity = Controller2D.BaseVelocity;

        // Handle jumping
        _jumpedThisFrame = false;

        if (_jumpRequested)
        {
            if (AllowDoubleJump)
            {
                // See if we actually are allowed to jump
                if ((!_doubleJumpConsumed && !_canWallJump && !_foundWall && ((AllowJumpingWhenSliding ? (!Controller2D.GroundingStatus.FoundAnyGround) : !Controller2D.GroundingStatus.IsStableOnGround))))
                {
                    // Calculate jump direction before ungrounding
                    Vector3 jumpDirection = Controller2D.CharacterUp;
                    if (Controller2D.GroundingStatus.FoundAnyGround && !Controller2D.GroundingStatus.IsStableOnGround)
                    {
                        //jumpDirection = Controller2D.GroundingStatus.GroundNormal;
                    }

                    // Makes the character skip ground probing/snapping on its next update.
                    // If this line weren't here, the character would remain snapped to the ground when trying to jump. Try commenting this line out and see.
                    Controller2D.ForceUnground();

                    // Add to the return velocity and reset jump state
                    Vector2 jum = (jumpDirection * JumpSpeed) - Vector3.Project(result.velocity, Controller2D.CharacterUp);
                    result.velocity     = result.velocity + jum;
                    _jumpRequested      = false;
                    _doubleJumpConsumed = true;
                    _jumpedThisFrame    = true;
                }
            }


            // See if we actually are allowed to jump
            if (_canWallJump ||
                (((AllowJumpingWhenSliding ? Controller2D.GroundingStatus.FoundAnyGround : Controller2D.GroundingStatus.IsStableOnGround))))
            {
                // Calculate jump direction before ungrounding
                Vector3 jumpDirection = Controller2D.CharacterUp;
                Vector3 up            = Controller2D.CharacterUp;

                if (_canWallJump)
                {
                    jumpDirection = Vector3.ProjectOnPlane(_wallJumpNormal, Controller2D.CharacterUp) + up;
                }
                else if (Controller2D.GroundingStatus.FoundAnyGround && !Controller2D.GroundingStatus.IsStableOnGround)
                {
                    //jumpDirection = Controller2D.GroundingStatus.GroundNormal;
                }

                // Makes the character skip ground probing/snapping on its next update.
                // If this line weren't here, the character would remain snapped to the ground when trying to jump. Try commenting this line out and see.
                Controller2D.ForceUnground();

                // Add to the return velocity and reset jump state
                Vector2 jum = (jumpDirection * JumpSpeed) - Vector3.Project(result.velocity, Controller2D.CharacterUp);
                //Vector2 vel = (_wallJumpNormal * 4);
                result.velocity += jum;
                _jumpRequested   = false;
                _jumpedThisFrame = true;
            }
        }


        if (AllowWallJump)
        {
            _canWallJump = _foundWall;
        }
        else
        {
            _canWallJump = false;
        }

        return(result);
    }