public override CharacterTask.Task getCurrentTask(CharacterTaskTracker taskTracker)
        {
            Actor toAttack = getNearestEnemyInAgroRange();

            if (toAttack != null)
            {
                float distToTarget = Vector3.Distance(character.getLocation(), toAttack.getLocation());
                if (distToTarget > loseInterestDistance || toAttack.isDead())
                {
                    return(new CharacterTask.NoTask());
                }
                else if (distToTarget > getDesiredDistanceFromTarget())
                {
                    return(new CharacterTask.WalkTowardPoint(toAttack.getLocation()));
                }
                else if (distToTarget < 1)
                {
                    Vector3 fromTargetToMe = (character.getFootLocation() - toAttack.getFootLocation());
                    fromTargetToMe.Normalize();
                    return(new CharacterTask.WalkTowardPoint(character.getFootLocation() + fromTargetToMe));
                }
                else
                {
                    //  return new CharacterTask.NoTask();
                    if (character.canSwing())
                    {
                        return(new CharacterTask.DoStrikeOfWorkAlongRay(character, character.getLocation(), character.getStrikeRange(), toAttack.getLocation() - character.getLocation()));
                    }
                    else
                    {
                        return(new CharacterTask.NoTask());
                    }
                }
            }
            if (character.getFaction() != Actor.Faction.friendly)
            {
                /* PathHandler pathHandler = new PathHandler();
                 * Path path = pathHandler.getPathToSingleBlock(pathingProfile,
                 *   new BlockLoc(character.getFootLocation()), pathingProfile,
                 *   BlockLoc.AddIntVec3(new BlockLoc(character.getFootLocation()), pathingProfile.getRandomMove()), 2);
                 * TravelAlongPath currentWalkJob = new TravelAlongPath(path, new AggressiveStanceJob(pathingProfile, actorProfile, character));
                 * if (currentWalkJob.isUseable())
                 * {
                 *  // return new CharacterTask.SwitchJob(currentWalkJob);
                 * }*/
                BlockLoc toTry = BlockLoc.AddIntVec3(new BlockLoc(character.getFootLocation()), World.getPathingProfile().getRandomMove());
                if (World.getPathingProfile().isStandableAtWithHeight(toTry, 2))
                {
                    List <BlockLoc> pathList = new List <BlockLoc>();
                    pathList.Add(toTry);
                    Path path = new Path(pathList);
                    return(new CharacterTask.SwitchJob(new TravelAlongPath(path, new AggressiveStanceJob(character))));
                }
            }

            return(new CharacterTask.NoTask());
        }
Example #2
0
 public override void getHit(float damage, Vector3 hitForceDirection, Actor striker)
 {
     recieveDamage(damage);
     hitForceDirection = applyKnockBack(hitForceDirection);
     setJobAndCheckUseability(new AttackActorJob(striker, World.getPathingProfile(), World.getActorProfile(), this));
 }
Example #3
0
        private List <AnimationType> UpdateJobTasks(List <ActorAction> actions, CharacterTaskTracker taskTracker)
        {
            CharacterTask.Task toDo = job.getCurrentTask(taskTracker);

            List <AnimationType> animations = new List <AnimationType>();

            switch (toDo.taskType)
            {
            case CharacterTask.Type.NoTask:
                //runPhysics(actions);
                animations.Add(AnimationType.standing);
                break;

            case CharacterTask.Type.StepToBlock:
                updateStepTask((CharacterTask.StepToBlock)toDo, animations);
                setVelocity(new Vector3());
                break;

            case CharacterTask.Type.DestoryBlock:
                animations.Add(AnimationType.standing);
                CharacterTask.DestroyBlock destroyBlock = (CharacterTask.DestroyBlock)toDo;
                actions.Add(new ActorStrikeBlockAction(this, destroyBlock.getBlockToDestroy(), JobType.mining));

                StartHammerAnimationIfPossible();
                break;

            case CharacterTask.Type.BuildBlock:
                animations.Add(AnimationType.standing);
                CharacterTask.BuildBlock buildBlock = (CharacterTask.BuildBlock)toDo;
                actions.Add(new ActorPlaceBlockAction(buildBlock.getBlockLocToBuild(), buildBlock.getBlockTypeToBuild()));
                StartHammerAnimationIfPossible();
                dropItem();
                break;

            case CharacterTask.Type.ChopBlockForFrame:
                animations.Add(AnimationType.standing);
                CharacterTask.ChopBlockForFrame chopBlock = (CharacterTask.ChopBlockForFrame)toDo;
                actions.Add(new ActorStrikeBlockAction(this, chopBlock.getBlockToChop(), JobType.logging));
                StartHammerAnimationIfPossible();
                break;

            case CharacterTask.Type.ObjectBuildForFrame:
                CharacterTask.ObjectBuildForFrame objectBuildTask = (CharacterTask.ObjectBuildForFrame)toDo;
                objectBuildTask.getSiteToWorkOn().buildForAFrame();
                if (objectBuildTask.getSiteToWorkOn().isReadyToBeBuilt())
                {
                    actions.Add(new ActorPlaceBoatAction(objectBuildTask.getSiteToWorkOn().getObjectLoc()));
                }
                StartHammerAnimationIfPossible();
                break;

            case CharacterTask.Type.CaptainBoat:
                //setRotationWithGivenDeltaVec(((CharacterTask.CaptainBoat)toDo).getBoat().getFootLocation() - getFootLocation());
                setFootLocation(((CharacterTask.CaptainBoat)toDo).getBoat().getLocation() + new Vector3(0, .6f, 0));
                setVelocity(new Vector3());
                break;

            case CharacterTask.Type.GetInBoat:
                getInBoat(((CharacterTask.GetInBoat)toDo).getBoat());
                break;

            case CharacterTask.Type.SwitchJob:
                setJobAndCheckUseability(((CharacterTask.SwitchJob)toDo).getNewJob());
                break;

            case CharacterTask.Type.WalkTowardPoint:
                animations.Add(AnimationType.walking);

                if (World.getPathingProfile().isActorStanding(this))
                {
                    Vector3 move = getWalkTowardDeltaVec(((CharacterTask.WalkTowardPoint)toDo).getTargetLoc());
                    move.Normalize();
                    move *= getWalkSpeedWhilePathing();
                    actions.Add(getAddVelocityAction(move, false));
                }


                setRotationWithGivenDeltaVec(((CharacterTask.WalkTowardPoint)toDo).getTargetLoc() - getLocation());

                break;

            case CharacterTask.Type.LookTowardPoint:

                animations.Add(AnimationType.standing);
                setRotationWithGivenDeltaVec(((CharacterTask.LookTowardPoint)toDo).getTargetLoc() - getLocation());
                break;

            case CharacterTask.Type.DoStrikeOfWorkAlongRay:

                animations.Add(AnimationType.standing);
                setRotationWithGivenDeltaVec(((CharacterTask.DoStrikeOfWorkAlongRay)toDo).getStrikeDirectionNormal());
                if (canSwing())
                {
                    CharacterTask.DoStrikeOfWorkAlongRay strike = (CharacterTask.DoStrikeOfWorkAlongRay)toDo;
                    StartStrikeAnimation();
                    swing();
                    actions.Add(new ActorStrikeAlongRayAction(this, strike.getStrikeOrigen(), strike.getStrikeDistance(), strike.getStrikeDirectionNormal(), JobType.combat, 0));
                }
                break;

            case CharacterTask.Type.MakeFarmBlockGrow:
                actions.Add(new ActorStrikeBlockAction(this, ((CharacterTask.MakeFarmBlockGrow)toDo).getBlockToFarm(), JobType.agriculture));
                StartHammerAnimationIfPossible();
                break;

            case CharacterTask.Type.HarvestFarmBlock:
                CharacterTask.HarvestFarmBlock harvestTask = (CharacterTask.HarvestFarmBlock)toDo;
                actions.Add(new ActorStrikeBlockAction(this, ((CharacterTask.HarvestFarmBlock)toDo).getBlockToFarm(),
                                                       JobType.agriculture));
                setJobAndCheckUseability(new CarryResourceToStockpileKickoffJob(ResourceBlock.ResourceType.Wheat, this,
                                                                                new FarmingKickoffJob(harvestTask.getFarm(), this, harvestTask.getWorkingProfile()), harvestTask.getWorkingProfile()));
                StartHammerAnimationIfPossible();
                pickUpItem(ResourceBlock.ResourceType.Wheat);
                break;

            case CharacterTask.Type.PlaceResource:
                CharacterTask.PlaceResource placeResource = (CharacterTask.PlaceResource)toDo;
                actions.Add(new ActorPlaceResourceAction(placeResource.getLocToPlaceResource(), placeResource.getTypeToPlace()));
                //StartHammerAnimationIfPossible();
                dropLoad();
                break;

            case CharacterTask.Type.PickUpResource:
                CharacterTask.PickUpResource pickUpResource = (CharacterTask.PickUpResource)toDo;
                actions.Add(new ActorPickUpResourceAction(pickUpResource.getLocToPlaceResource(), pickUpResource.getTypeToPlace()));
                load.pickUpItem(pickUpResource.getTypeToPlace());
                StartHammerAnimationIfPossible();
                pickUpItem(pickUpResource.getTypeToPlace());
                break;

            default:
                throw new Exception("unhandled task");
            }
            if (job.isComplete())
            {
                job = new UnemployedJob();
            }
            return(animations);
        }