Esempio n. 1
0
    public FixVector2 calculateGoalTeamMovePosition(FixVector2 targetPosition, Fix64 minRadius, Fix64 maxRadius)
    {
        var direction    = (actor.getPosition() - targetPosition).normalized;
        var randomRadius = minRadius + (maxRadius - minRadius) * world.randomUnit;

        return(targetPosition + direction * randomRadius);
    }
Esempio n. 2
0
 public EBTStatus run(FixVector2 position, Fix64 startDistance, Fix64 stopDistance)
 {
     //if (actor.id == 5)
     //{
     //    UnityEngine.Debug.LogError("run position:" + position);
     //}
     if (state != PlayerState.Move)
     {
         //if (state == PlayerState.Shoot && actor.id == 9)
         //{
         //    Debuger.LogError("  shoot to move !!!");
         //}
         if (isArrivedPosition(position, startDistance))
         {
             //if (actor.id == 5)
             //{
             //    UnityEngine.Debug.Log("run  BT_SUCCESS");
             //}
             return(EBTStatus.BT_SUCCESS);
         }
         state = PlayerState.Move;
     }
     if (isArrivedPosition(position, stopDistance))
     {
         //if (actor.id == 5)
         //{
         //    UnityEngine.Debug.Log("run  BT_SUCCESS");
         //}
         return(EBTStatus.BT_SUCCESS);
     }
     //LogicEvent.fire("onTestDrawPosition", position, stopDistance);
     movingTarget    = position;
     arriveThreshold = stopDistance;
     return(EBTStatus.BT_RUNNING);
 }
Esempio n. 3
0
        void _beforeFlyCatching(FBActor actor, Fix64 deltaTime)
        {
            actor.m_timer -= deltaTime;
            if (actor.m_timer <= Fix64.Zero)
            {
                //Debuger.Log("_beforeFlyCatching end begin move frameNumber:" + actor.world.world.frameCount);

                actor.m_timer = actor.m_cathingBallStateAniWaitTime;
                if (actor.m_stateBool && (actor.m_stateDataIndex == 3 || actor.m_stateDataIndex == 4))
                {
                    actor.m_stateInt = 0;//接不到球
                }
                else
                {
                    actor.m_stateInt = 1;//接到球
                }
                Fix64 verticleSpeed = _getActorVelocity(actor, actor.m_timer, out actor.m_cathingBallStateMovingVelocity);
                actor.particle.dampingAcceleration = Fix64.Zero;
                actor.m_stateSubState = (int)SubState.kFlyCatching;
                actor.m_cathingBallStateVerticleSpeed = verticleSpeed;
                //开始播放接球动画
                actor.world.onDoorKeeperCatchingBall(actor,
                                                     actor.m_stateDataIndex,
                                                     FixVector2.cross(actor.direction, actor.m_stateVector - actor.getPosition()) < Fix64.Zero);

                return;
            }
        }
Esempio n. 4
0
    public FixVector2 GetNormalized()
    {
        FixVector2 v = new FixVector2(this);

        v.Normalize();
        return(v);
    }
Esempio n. 5
0
    //某个角色开始传球
    //短传0,长传1
    public void beginPassBall(FBActor actor, FixVector2 passBallDirection, int index)
    {
        //Debuger.Log("beginPassBall...........");

        Fix64 maxR  = m_ball.owner.configuration.passBallMaxR[index];
        Fix64 minR  = m_ball.owner.configuration.passBallMinR[index];
        Fix64 angle = m_ball.owner.configuration.passBallFov[index];
        Fix64 bestR = m_ball.owner.configuration.passBallBestR[index];

        //没有键入方向,使用角色朝向
        if (passBallDirection == FixVector2.kZero)
        {
            passBallDirection = actor.direction;
        }

        FBActor target = findTarget(m_ball.owner, passBallDirection, index, (int)m_ball.owner.team, m_ball.owner);

        if (target != null)
        {
            passBallDirection = target.getPosition() - m_ball.owner.getPosition();
            passBallDirection = passBallDirection.normalized;
        }

        FixVector2 actorFaceDirection = getAjustedDirection(actor.direction, passBallDirection, actor.configuration.passBallAngleTorelance[index]);

        actor.doPassBall(index, actorFaceDirection);

        //保存传球对象
        passBallType   = index;
        passBallTarget = target;
        passBallDir    = passBallDirection;
    }
Esempio n. 6
0
 public Layout(Orientation orientation, FixVector2 size, FixVector2 origin, bool initialized = true)
 {
     this.orientation = orientation;
     this.size        = size;
     this.origin      = origin;
     this.initialized = initialized;
 }
Esempio n. 7
0
        public override void enter(FBActor actor)
        {
            actor.m_stateSubState = (int)SubState.kBeforePassing;
            actor.m_timer         = actor.m_configuration.pb_beforePassingTime[actor.m_stateDataIndex];
            var   cos = FixVector2.dot(actor.m_direction, actor.m_stateVector);
            Fix64 ralativeDirection = Fix64.Zero;

            if (cos < Fix64.One)
            {
                var sin = Fix64.Sqrt(Fix64.One - cos * cos);

                ralativeDirection = FixVector2.cross(actor.m_direction, actor.m_stateVector);
                if (ralativeDirection >= Fix64.Zero)
                {
                    sin = -sin;
                }
                actor.m_stateValue = Fix64.Atan2(sin, cos);
            }
            else
            {
                actor.m_stateValue = Fix64.Zero;
            }

            int passBallFoot = actor.getKickBallFoot(actor.m_stateVector, actor.m_direction);

            actor.world.onPassBallBegin(actor, actor.m_stateDataIndex == 0, passBallFoot == 1);
        }
Esempio n. 8
0
    //检测源和目标之间是否被阻挡
    bool checkBlocked(FBActor src, FBActor target)
    {
        FixVector2 a = (target.getPosition() - src.getPosition()).normalized;

        for (int i = 0; i < m_actors.Count; i++)
        {
            var actor = m_actors[i];
            if (actor == src || actor == target)
            {
                continue;
            }

            FixVector2 c       = actor.getPosition() - src.getPosition();
            Fix64      dotData = FixVector2.dot(c, a);
            if (dotData <= Fix64.Zero)
            {
                continue;
            }
            Fix64 d = c.squareLength - Fix64.FastAbs(dotData * dotData);
            if (d < ball.configuration.radius * ball.configuration.radius)
            {
                return(true);
            }
        }

        return(false);
    }
Esempio n. 9
0
    public Fix64 getTargetDistance(FixVector2 target)
    {
        var distance = actor.getPosition().distance(target);

        //Debuger.Log("distance : " + distance);
        return(distance);
    }
Esempio n. 10
0
    public FixVector2 getRandomPosition()
    {
        var penaltyareaSize = world.config.penaltyAreaSize;
        var realSize        = penaltyareaSize * (Fix64)0.8;
        var randomX         = world.randomUnit;
        var randomY         = world.randomUnit;
        //Debuger.Log("randomX:" + randomX + " randomY:" + randomX);
        var randomPosition = new FixVector2
        {
            x = -realSize.x + (Fix64)2 * realSize.x * randomX,
            y = -realSize.y + (Fix64)2 * realSize.y * randomY,
        };
        var doorPosition      = actor.getSelfDoorPosition();
        var penaltyareaCenter = FixVector2.kZero;

        if (doorPosition.x > Fix64.Zero)
        {
            penaltyareaCenter = doorPosition - new FixVector2 {
                x = penaltyareaSize.x * (Fix64)1.2
            };
        }
        else
        {
            penaltyareaCenter = doorPosition + new FixVector2 {
                x = penaltyareaSize.x * (Fix64)1.2
            };
        }
        return(penaltyareaCenter + randomPosition);
    }
Esempio n. 11
0
 void onBallLanded(FixVector2 point, bool pass, int times, FixVector3 velocity, Fix64 preHeightVelocity)
 {
     if (times == 1)
     {
         endShoot();
     }
 }
Esempio n. 12
0
    public void willCatchBall(FBActor actor, FixVector2 target, Fix64 time)
    {
        m_willBeCatched      = true;
        m_willBeCatchedActor = actor;

        m_particle.notify_willCatchInLand(target, time);
    }
Esempio n. 13
0
        public override void enter(FBActor actor)
        {
            FixVector2 targetPosition = actor.world.ball.particlePosition + actor.world.ball.particleVelocity * actor.configuration.tcb_normalTime;

            //Debuger.Log("TigerCatchingBall currentBallPos:"
            //    + (UnityEngine.Vector2)actor.world.ball.particlePosition
            //    + " TargetPostion " + targetPosition
            //    + " NeedTime:" + (float)actor.configuration.tcb_normalTime
            //    + " actor.world.ball.particleVelocity:" + (UnityEngine.Vector2)actor.world.ball.particleVelocity);

            actor.world.ball.willCatchBall(actor, targetPosition, actor.configuration.tcb_normalTime);

            FixVector2 targetPositionVelocity = targetPosition - actor.getPosition();
            Fix64      distance = targetPositionVelocity.length;

            targetPositionVelocity             = targetPositionVelocity / distance;
            actor.m_stateVector                = targetPositionVelocity * (distance / actor.configuration.tcb_normalTime);
            actor.particle.dampingAcceleration = Fix64.Zero;
            actor.direction = targetPositionVelocity;

            actor.m_stateSubState = (int)SubState.kBeforeCatching;
            actor.m_timer         = actor.configuration.tcb_normalTime;

            actor.world.onActorTigerCatchingBallBegin(actor);
        }
Esempio n. 14
0
    DefendMoveDirection getMoveDirection()
    {
        Fix64 cosAngle = FixVector2.dot(direction, moveDirection);

        if (cosAngle > Fix64.Cos(configuration.dm1_angleA))
        {
            return(DefendMoveDirection.Forward);
        }
        else if (cosAngle < Fix64.Cos(configuration.dm1_angleB))
        {
            return(DefendMoveDirection.Back);
        }
        else
        {
            Fix64 cross = FixVector2.cross(direction, moveDirection);
            if (cross < Fix64.Zero)
            {
                return(DefendMoveDirection.Right);
            }
            else
            {
                return(DefendMoveDirection.Left);
            }
        }
    }
Esempio n. 15
0
 public bool isInRange(FixVector2 position)
 {
     return(-m_mainExtent.x < position.x &&
            position.x < m_mainExtent.x &&
            -m_mainExtent.y < position.y &&
            position.y < m_mainExtent.y);
 }
Esempio n. 16
0
        void _beforeShooting(FBActor actor, Fix64 deltaTime)
        {
            actor.m_particle.dampingAcceleration = actor.m_configuration.m1_stopDampingAcceleration_ball;
            actor.m_timer -= deltaTime;
            if (actor.m_timer < Fix64.Zero)
            {
                if (actor.m_direction != actor.m_stateVector)
                {
                    actor.m_direction         = actor.m_stateVector;
                    actor.m_particle.velocity = actor.m_direction * actor.m_particle.velocity.length;
                }
                actor.m_stateSubState = (int)SubState.kAfterShooting;
                actor.m_timer         = actor.m_configuration.sb_afterShootingTime[actor.m_stateDataIndex];

                if (actor.m_stateDataIndex == (int)(ShootType.Killer))
                {
                    actor.world.fbGame.logicTimeScale = (Fix64)1.0f;
                }

                actor.world.shootBallOutEvent = true;

                return;
            }

            if (actor.m_direction != actor.m_stateVector)
            {
                var angle = actor.m_stateValue * (actor.m_timer / actor.m_configuration.sb_beforeShootingTime[actor.m_stateDataIndex]);
                var cos   = Fix64.Cos(angle);
                var sin   = Fix64.Sin(angle);
                actor.m_direction.x       = FixVector2.dot(actor.m_stateVector, new FixVector2(cos, -sin));
                actor.m_direction.y       = FixVector2.dot(actor.m_stateVector, new FixVector2(sin, cos));
                actor.m_particle.velocity = actor.m_direction * actor.m_particle.velocity.length;
            }
        }
Esempio n. 17
0
        void processRotation(FBActor actor, FixVector2 moveDirection, bool tween, Fix64 maxAngle)
        {
            var speed = actor.m_particle.velocity.length;

            if (tween)
            {
                var cos     = FixVector2.dot(actor.m_direction, moveDirection);
                var cos_max = Fix64.Cos(maxAngle);

                if (cos >= cos_max)
                {
                    actor.m_direction = moveDirection;
                }
                else
                {
                    var sin_max =
                        FixVector2.cross(actor.m_direction, moveDirection) >= Fix64.Zero ?
                        Fix64.Sin(maxAngle) : Fix64.Sin(-maxAngle);

                    actor.m_direction = new FixVector2()
                    {
                        x = FixVector2.dot(actor.m_direction, new FixVector2(cos_max, -sin_max)),
                        y = FixVector2.dot(actor.m_direction, new FixVector2(sin_max, cos_max))
                    };
                }
            }
            else
            {
                actor.m_direction = moveDirection;
            }

            actor.m_particle.velocity = actor.m_direction * speed;
        }
Esempio n. 18
0
        private bool processCatchBallHelper(FBActor actor, ref FixVector2 moveDirection)
        {
            if (!actor.catchBallHelperEnabled || actor.world.ball.owner != null)
            {
                return(false);
            }
            if (actor.world.ball.particleHeight > actor.m_configuration.maxCatchingBallHelperHeight)
            {
                return(false);
            }
            var v  = actor.world.ball.particlePosition - actor.m_particle.position;
            var sd = v.squareLength;

            if (sd > actor.m_configuration.catchBallHelper_Raidus * actor.m_configuration.catchBallHelper_Raidus)
            {
                return(false);
            }
            var vu = v / Fix64.Sqrt(sd);

            if (FixVector2.dot(actor.m_direction, vu) < actor.m_configuration.catchBallHelper_MaxFanAngleCos)
            {
                return(false);
            }
            if (FixVector2.dot(moveDirection, vu) < actor.m_configuration.catchBallHelper_MaxAngleCos)
            {
                return(false);
            }
            if (actor.world.ball.particleVelocity.squareLength > actor.m_configuration.catchBallHelper_BallMaxSpeed.square)
            {
                return(false);
            }

            moveDirection = vu;
            return(true);
        }
Esempio n. 19
0
        void _prepareShooting(FBActor actor, Fix64 deltaTime)
        {
            if (actor.shootBallEvent)
            {
                actor.m_stateSubState = (int)SubState.kBeforeShooting;
                actor.m_timer         = actor.m_configuration.sb_beforeShootingTime[actor.m_stateDataIndex];
                var cos = FixVector2.dot(actor.m_direction, actor.m_stateVector);
                if (cos < Fix64.One)
                {
                    var sin = Fix64.Sqrt(Fix64.One - cos * cos);
                    if (FixVector2.cross(actor.m_direction, actor.m_stateVector) >= Fix64.Zero)
                    {
                        sin = -sin;
                    }
                    actor.m_stateValue = Fix64.Atan2(sin, cos);
                }
                else
                {
                    actor.m_stateValue = Fix64.Zero;
                }

                if (actor.m_stateDataIndex == (int)(ShootType.Killer))
                {
                    actor.world.fbGame.logicTimeScale = (Fix64)0.01f;
                }

                //
                actor.world.onShootBallReady(actor);

                return;
            }

            actor.m_particle.dampingAcceleration = actor.m_configuration.m1_stopDampingAcceleration_ball;

            if (actor.m_direction != actor.m_stateVector)
            {
                var cos      = FixVector2.dot(actor.m_direction, actor.m_stateVector);
                var maxAngle = actor.m_configuration.sb_angularSpeed * deltaTime;
                var cos_max  = Fix64.Cos(maxAngle);
                var speed    = actor.m_particle.velocity.length;
                if (cos >= cos_max)
                {
                    actor.m_direction = actor.m_stateVector;
                }
                else
                {
                    var sin_max =
                        FixVector2.cross(actor.m_direction, actor.m_stateVector) >= Fix64.Zero ?
                        Fix64.Sin(maxAngle) : Fix64.Sin(-maxAngle);

                    actor.m_direction = new FixVector2()
                    {
                        x = FixVector2.dot(actor.m_direction, new FixVector2(cos_max, -sin_max)),
                        y = FixVector2.dot(actor.m_direction, new FixVector2(sin_max, cos_max))
                    };
                }
                actor.m_particle.velocity = actor.m_direction * speed;
            }
        }
Esempio n. 20
0
    Edge calculateSlopeEdge(FixVector2 point)
    {
        var slopeEdge = m_edges[point.x > Fix64.Zero ? 2 : 3];
        var ratio     = Fix64.Clamp(point.y / m_doorHeight, Fix64.Zero, Fix64.One);

        slopeEdge.d += doorSlopeExtent * (Fix64)2 * (Fix64.One - ratio);
        return(slopeEdge);
    }
Esempio n. 21
0
    public bool isArrivedPosition(FixVector2 target, Fix64 threshold)
    {
        var distance  = getTargetDistance(target);
        var isArrived = distance < (threshold < Fix64.Zero ? Fix64.Zero : threshold);

        //Debuger.Log("isArrivedPosition distance " + distance);
        return(isArrived);
    }
 public void Reset()
 {
     mousePos    = FixVector2.Zero;
     inputUV     = FixVector2.Zero;
     isInputFire = false;
     skillId     = 0;
     isSpeedUp   = false;
 }
        //public override void Serialize(Serializer writer){
        //    writer.Write(mousePos);
        //    writer.Write(inputUV);
        //    writer.Write(isInputFire);
        //    writer.Write(skillId);
        //    writer.Write(isSpeedUp);
        //}

        public PlayerInput(MGameInput input)
        {
            _gameInput  = input;
            isInputFire = input.IsInputFire;
            skillId     = input.SkillId;
            isSpeedUp   = input.IsSpeedUp;
            mousePos    = new FixVector2(input.MousePos[0], input.MousePos[1]);
        }
Esempio n. 24
0
 public void collide(FixVector2 normal, Fix64 restitution)
 {
     if (m_owner != null)
     {
         return;
     }
     m_particle.notify_collideWith(normal, restitution);
 }
Esempio n. 25
0
 public void setup(FixVector2 mainExtent, FixVector2 doorExtent, Fix64 doorHeight, Fix64 doorSlopeExtent)
 {
     m_mainExtent = mainExtent;
     m_doorExtent = doorExtent;
     m_doorHeight = doorHeight;
     m_arena.build(mainExtent, doorExtent, doorHeight, doorSlopeExtent);
     onWorldCreated();
 }
Esempio n. 26
0
        public BTConfiguration(FixVector2 worldSize)
        {
            testIntConst   = 1;
            testFloatConst = Fix64.Zero;
            testFloatConst = (Fix64)0;
            testBoolConst  = true;


            //射门相关参数
            shootBaseScore                   = 500;
            shootScoreStandard               = 380;
            shootPositionDistanceRate        = (Fix64)5;
            shootPlayerAroundDangerScoreRate = (Fix64)1;
            shootPlayerSelfPassBallScore     = 150;
            shootPlayerPassBallScoreRate     = (Fix64)0.8;
            shootAreaEnemyEffect             = (Fix64)20;
            shootAreaTeamEffect              = (Fix64)5;
            shootAreaAroundEnemyEffect       = (Fix64)5;
            shootPositionAngleRate           = (Fix64)0;

            //球员周围危险分数相关参数
            aroundDangerBaseScore = 40;
            aroundDangerRange     = (Fix64)10;
            //aroundDangerRange *= aroundDangerRange;
            aroundDangerDistanceRate = (Fix64)4;
            //传球相关参数
            passBallBaseScore    = 150;
            passBallDistanceRate = (Fix64)10;
            passBallBestDistance = (Fix64)28;
            //passBallBestDistance *= passBallBestDistance;
            passBallEnemyEffect           = (Fix64)10;
            passBallTypeDistance          = (Fix64)15;
            passBallScoreShootScoreEffect = (Fix64)0.3;
            //基础参数
            playerSpeed    = (Fix64)7;
            ballShootSpeed = (Fix64)50;


            coachBTPath           = "Coach/CoachSubTree/";
            playerBTPath          = "Coach/Player/";
            gkBTPath              = "GKCoach/GK";
            coachUpdateInterval   = 5;
            gkCoachUpdateInterval = 5;
            gkPassBallWaitTime    = (Fix64)1;

            minChargeTime = (Fix64)0.2;

            mainGridRadius = (Fix64)2.5;

            sideExtendSize   = 5;
            minColWithBorder = 3;

            initPoints(worldSize);
            initDistances();
            initGrids();
        }
Esempio n. 27
0
 public bool doSliding(FixVector2 direction)
 {
     if (_setNextState(Sliding.instance, false))
     {
         this.direction = direction;
         m_currentState.enter(this);
         return(true);
     }
     return(false);
 }
Esempio n. 28
0
    public void shootBallDirectly(FBActor actor, ShootType type)
    {
        var direction = (actor.getEnemyDoorPosition() - actor.getPosition()).normalized;

        FixVector2 doorPosition  = FixVector2.kZero;
        FixVector2 destDirection = FixVector2.kZero;

        positiveDoorSide = getDoorSide(actor, direction, out destDirection);
        actor.shootBallDirectly(type, direction);
    }
Esempio n. 29
0
    // 中传
    public void freeByNormalPass(FixVector3 start, FixVector2 target, Fix64 airTime, Fix64 landTime)
    {
        if (m_owner == null)
        {
            return;
        }
        m_particle.notify_airLandBall(new FixVector2(start.x, start.z), start.y, target, airTime, landTime, m_configuration.linearDamping_air, m_configuration.linearDamping_land, m_configuration.landHitDamping);

        _free_common(BallState.PassBall);
    }
Esempio n. 30
0
    public void doSliding(FBActor actor)
    {
        FBActor        controlBallActor = null;
        List <FBActor> temp             = new List <FBActor>();

        for (int i = 0; i < m_actors.Count; ++i)
        {
            FBActor target = m_actors[i];
            if (target == actor || target.ignoreCollision)
            {
                continue;
            }
            if (target.team == actor.team)
            {
                continue;
            }
            if (target.isDoorKeeper())
            {
                continue;
            }

            FixVector2 relativePos = target.getPosition() - actor.getPosition();
            if (relativePos.squareLength > actor.configuration.st_maxSlidingTargetDistance.square)
            {
                continue;
            }

            if (FixVector2.dot(actor.direction, relativePos.normalized) < Fix64.Cos(actor.configuration.st_maxSlidingTargetAngle))
            {
                continue;
            }

            if (target.isCtrlBall())
            {
                controlBallActor = target;
                break;
            }
            temp.Add(target);
        }

        if (controlBallActor != null)
        {
            actor.doSliding((controlBallActor.getPosition() - actor.getPosition()).normalized);
        }
        else if (temp.Count == 0)
        {
            actor.doSliding(actor.direction);
        }
        else
        {
            FixVector2 preferPoint = actor.getPosition();
            temp.Sort(new FBActorTargetFindCompare(preferPoint));
            actor.doSliding((temp[0].getPosition() - actor.getPosition()).normalized);
        }
    }
Esempio n. 31
0
 public MoveCommand(uint target, FixVector2 position)
 {
     Target = target;
     Position = position;
 }