Beispiel #1
0
 public bool CanIGrabU(MovingEntity playerAsking)
 {
     if (!enabled)
     {
         return(false);
     }
     if (!pullable)
     {
         return(false);
     }
     if (playerAsking == playerThrowing)
     {
         return(false);
     }
     if (timeSinceSpawned < timeUntilCanGrab)
     {
         return(false);
     }
     if (playerPulling != null && playerPulling != playerAsking)
     {
         return(false);
     }
     return(true);
 }
Beispiel #2
0
        public void UpdatePathing()
        {
            MovingEntity body = GetComponent <MovingEntity>();

            if (pathingTarget == null)
            {
                body.desiredMove = Vector3.zero;
            }
            if (PhysicsUtils.millis() - lastPathfind > 1000.0 / pathfindsPerSecond)
            {
                LVector3       myPos           = LVector3.FromUnityVector3(transform.position);
                RaycastResults blockStandingOn = body.BlockStandingOn();
                // if we are using shift and standing over an empty block, but our feet are on a neighboring block, use that neighboring block for pathfinding instead
                if (blockStandingOn != null)
                {
                    myPos = blockStandingOn.hitBlock + new LVector3(0, blocksHeight, 0);
                }

                ////// new stuff
                // find position on ground below player and path to that instead
                LVector3 playerPos    = LVector3.FromUnityVector3(pathingTarget.transform.position);
                int      goDownAmount = 10; // don't get into infinite loop, give up eventually
                while (playerPos.BlockV == BlockValue.Air && goDownAmount > 0)
                {
                    playerPos = playerPos - new LVector3(0, 1, 0);
                    goDownAmount--;
                }
                playerPos += new LVector3(0, 2, 0);
                //////


                bool iShouldJump = true;


                //// new stuff

                /*
                 * bool pathingSuccess = false;
                 * PathingSpreadNode resPath = BlocksPathing.Pathfind(World.mainWorld, myPos, playerPos, 1, 1, blocksHeight, 1, out pathingSuccess);
                 * iShouldJump = true;
                 * if (resPath != null)
                 * {
                 *  curPath = (new PathingResult(resPath)).GetPathNode();
                 * }
                 */
                /////

                //PhysicsUtils.Pathfind(blocksHeight, ref curPath, out iShouldJump, myPos, playerPos, 200);

                if (iShouldJump)
                {
                    body.jumping = true;
                }
                lastPathfind = PhysicsUtils.millis();
            }

            body.desiredMove = Vector3.zero;
            Vector3 targetPos = transform.position;

            if (curPath != null)
            {
                LVector3 myPos           = LVector3.FromUnityVector3(transform.position);
                LVector3 myPosBeforeJump = myPos - new LVector3(0, 1, 0);
                if (curPath.prevNode != null && (myPos == curPath.prevNode.pos || myPosBeforeJump == curPath.prevNode.pos))
                {
                }
                else if (curPath.nextNode != null && (myPos == curPath.nextNode.pos || myPosBeforeJump == curPath.nextNode.pos))
                {
                    curPath = curPath.nextNode;
                }
                else if (myPos == curPath.pos || myPosBeforeJump == curPath.pos)
                {
                    if (curPath.nextNode != null)
                    {
                        curPath = curPath.nextNode;
                    }
                }

                LVector3 targetBlock = curPath.pos;
                if (targetBlock.y == LVector3.FromUnityVector3(transform.position).y)
                {
                    body.usingShift = true;
                }
                else
                {
                    body.usingShift = false;
                }
                if (targetBlock.y > myPos.y)
                {
                    body.jumping = true;
                }
                else
                {
                    body.jumping = false;
                }
                targetPos = targetBlock.BlockCentertoUnityVector3();
                body.SetAbsoluteDesiredMove((targetPos - transform.position).normalized);
            }
        }
Beispiel #3
0
        public void UpdateOld()
        {
            MovingEntity body = GetComponent <MovingEntity>();

            if (PhysicsUtils.millis() - lastPathfind > 1000.0 / pathfindsPerSecond)
            {
                LVector3       myPos           = LVector3.FromUnityVector3(transform.position);
                RaycastResults blockStandingOn = body.BlockStandingOn();
                // if we are using shift and standing over an empty block, but our feet are on a neighboring block, use that neighboring block for pathfinding instead
                if (blockStandingOn != null)
                {
                    myPos = blockStandingOn.hitBlock + new LVector3(0, blocksHeight, 0);
                }
                LVector3 playerPos = LVector3.FromUnityVector3(FindObjectOfType <BlocksPlayer>().transform.position);
                bool     iShouldJump;
                PhysicsUtils.Pathfind(blocksHeight, ref curPath, out iShouldJump, myPos, playerPos, 200);

                if (iShouldJump)
                {
                    body.jumping = true;
                }
                lastPathfind = PhysicsUtils.millis();
            }

            body.desiredMove = Vector3.zero;
            Vector3 targetPos = transform.position;

            if (curPath != null)
            {
                LVector3 myPos           = LVector3.FromUnityVector3(transform.position);
                LVector3 myPosBeforeJump = myPos - new LVector3(0, 1, 0);
                if (curPath.prevNode != null && (myPos == curPath.prevNode.pos || myPosBeforeJump == curPath.prevNode.pos))
                {
                }
                else if (curPath.nextNode != null && (myPos == curPath.nextNode.pos || myPosBeforeJump == curPath.nextNode.pos))
                {
                    curPath = curPath.nextNode;
                }
                else if (myPos == curPath.pos || myPosBeforeJump == curPath.pos)
                {
                    if (curPath.nextNode != null)
                    {
                        curPath = curPath.nextNode;
                    }
                }
                else if (myPos != curPath.pos && myPosBeforeJump != curPath.pos && curPath.prevNode != null)
                {
                    //curPath = curPath.prevNode;
                }

                /*
                 * while (myPos != curPath.pos && myPosBeforeJump != curPath.pos)
                 * {
                 *  if (curPath.nextNode == null)
                 *  {
                 *      break;
                 *  }
                 *  else
                 *  {
                 *      curPath = curPath.nextNode;
                 *  }
                 * }
                 */

                //if (myPos == curPath.pos || myPosBeforeJump == curPath.pos)
                // {
                LVector3 targetBlock = curPath.pos;
                if (targetBlock.y == LVector3.FromUnityVector3(transform.position).y)
                {
                    body.usingShift = true;
                }
                else
                {
                    body.usingShift = false;
                }
                if (curPath.nextNode != null)
                {
                    //targetBlock = curPath.nextNode.pos;
                }
                if (targetBlock.y > myPos.y)
                {
                    body.jumping = true;
                }
                else
                {
                    body.jumping = false;
                }
                targetPos = targetBlock.BlockCentertoUnityVector3();
                body.SetAbsoluteDesiredMove((targetPos - transform.position).normalized);
                //}
                //else
                //{
                // }
            }

            /*
             * if (curPath != null && curPath.nextNode != null)
             * {
             *  //PathNode next = curPath;
             *  //while (Vector3.Distance(next.pos.BlockCentertoUnityVector3(), transform.position) < 1.0f && next.nextNode != null)
             *  //{
             *  //    next = next.nextNode;
             *  //}
             *  targetPos = curPath.nextNode.pos.BlockCentertoUnityVector3();
             *  //LVector3 playerPos = LVector3.FromUnityVector3(FindObjectOfType<BlocksPlayer>().transform.position);
             *  //Debug.Log("going to " + curPath.nextNode.pos.BlockCentertoUnityVector3() + " player position is " + FindObjectOfType<BlocksPlayer>().transform.position + " player block pos is " + playerPos);
             *  //body.SetAbsoluteDesiredMove((curPath.nextNode.pos.BlockCentertoUnityVector3() - transform.position));
             *  //body.jumping = true;
             * }
             * else if (curPath != null)
             * {
             *  //Debug.Log("going to " + curPath.nextNode.pos.BlockCentertoUnityVector3() + " player position is " + FindObjectOfType<BlocksPlayer>().transform.position + " player block pos is " + playerPos);
             *  // body.SetAbsoluteDesiredMove((curPath.pos.BlockCentertoUnityVector3() - transform.position));
             *  targetPos = curPath.pos.BlockCentertoUnityVector3();
             *  //body.jumping = true;
             * }
             * LVector3 targetBlock = LVector3.FromUnityVector3(targetPos);
             * LVector3 myBlock = LVector3.FromUnityVector3(transform.position - new Vector3(0, body.heightBelowHead / 2.0f, 0));
             * if (targetBlock.y > myBlock.y)
             * {
             *  body.jumping = true;
             * }
             * else
             * {
             *  body.jumping = false;
             * }
             * body.SetAbsoluteDesiredMove((targetPos - transform.position)+Random.insideUnitSphere*0.1f);
             */
            /*
             * Vector3 curOff = Random.insideUnitCircle;
             * offset += curOff * 0.1f;
             * if (offset.magnitude > 1.0f)
             * {
             *  offset = offset.normalized * 1.0f;
             * }
             * if (Random.value < 0.01f)
             * {
             *  body.jumping = true;
             * }
             * else
             * {
             *  body.jumping = false;
             * }
             * body.desiredMove = offset;
             */
        }
Beispiel #4
0
        // Update is called once per frame
        void Update()
        {
            if (movingEntity == null)
            {
                movingEntity = GetComponent <MovingEntity>();
            }
            if (playerPulling != null)
            {
                transform.position += movingEntity.GetVel() * Time.deltaTime + movingEntity.desiredMove * Time.deltaTime;
                //movingEntity.SetVel(movingEntity.GetVel() * 0.99f);
            }


            timeSinceSpawned += Time.deltaTime;

            if (blockName != "")
            {
                try
                {
                    blockId = BlockUtils.StringToBlockId(blockName);
                    if (blockStack != null)
                    {
                        blockStack.block = blockId;
                    }
                    blockName = "";
                }
                catch
                {
                }
            }

            if (movingEntity != null && movingEntity.IsTouchingGround())
            {
                movingEntity.desiredMove *= 0.9f;
            }

            if (playerThrowing != null)
            {
                movingEntity.speed = 5.0f;
                if (movingEntity.IsTouchingGround())
                {
                    //movingEntity.desiredMove *= 0.9f;
                }
                if (Time.time - timeThrown > 3.3f)
                {
                    playerThrowing = null;
                }
            }
            if (blockStack == null)
            {
                blockStack = new BlockStack(blockId, 1);
            }
            if (blockStack != null)
            {
                if (blockStack.count <= 0)
                {
                    blockStack = null;
                }
                else
                {
                    blockId = blockStack.block;
                    if (transform.GetComponentInChildren <UnityEngine.UI.Text>() != null)
                    {
                        if (blockStack.count > 1)
                        {
                            transform.GetComponentInChildren <UnityEngine.UI.Text>().text = blockStack.count + "";
                        }
                        else
                        {
                            transform.GetComponentInChildren <UnityEngine.UI.Text>().text = "";
                        }
                    }
                }
            }

            if (playerPulling != null || !pullable)
            {
                if (movingEntity != null)
                {
                    movingEntity.enabled = false;
                }
            }
            if (playerPulling == null && pullable)
            {
                if (movingEntity != null)
                {
                    movingEntity.enabled = true;
                }
            }


            if (playerPulling == null && movingEntity != null && movingEntity.enabled)
            {
                if (movingEntity.IsTouchingGround() && informStuffBelow.Do())
                {
                    RaycastResults blockStandingOn = movingEntity.BlockStandingOn();
                    //Debug.Log("checking below entity, hit block " + BlockValue.IdToBlockName(blockStandingOn.hitBlock.Block));

                    Blocks.BlockOrItem customBlock;
                    if (World.mainWorld.customBlocks.ContainsKey(blockStandingOn.hitBlock.Block, out customBlock))
                    {
                        //Debug.Log("calling block stack above on it");
                        using (BlockData hitBlockData = World.mainWorld.GetBlockData(blockStandingOn.hitBlock))
                        {
                            BlockStack myStack = Stack;
                            BlockStack resStack;
                            customBlock.BlockStackAbove(hitBlockData, myStack, transform.position, out resStack);

                            if (resStack == null || resStack.count <= 0 || resStack.block == BlockValue.Air)
                            {
                                Destroy(transform.gameObject);
                            }
                            else
                            {
                                Stack = resStack;
                            }
                        }
                    }
                }
            }
            if (GetComponent <UnityEngine.UI.Outline>() != null)
            {
                GetComponent <UnityEngine.UI.Outline>().enabled = selected;
            }

            if (GetComponentInChildren <DurabilityBar>() != null)
            {
                DurabilityBar bar = GetComponentInChildren <DurabilityBar>();
                bar.enabled = blockStack != null && blockStack.maxDurability != 0;
                if (bar.enabled)
                {
                    bar.durability = blockStack.durability / (float)blockStack.maxDurability;
                }
            }

            UpdateTexture();

            if (pullable)
            {
                transform.rotation *= Quaternion.Euler(0, 12.0f * Time.deltaTime, 0);
            }
        }
Beispiel #5
0
        public void Update()
        {
            this.typeOfThingDoing = this.thingDoing.typeOfThing;
            if (world == null)
            {
                world = World.mainWorld;

                if (world == null) // not initialized yet, wait
                {
                    return;
                }
            }

            if (updateAction.Do())
            {
                //Debug.Log("updating action");
                float totalWeight = 0.0f;
                for (int i = 0; i < actionWeights.Length; i++)
                {
                    actionWeights[i] = actionBaseWeights[i] + GetWeight((TypeOfThingDoing)i);
                    if (isImportant[i])
                    {
                        actionWeights[i] = zeroOneThing(actionWeights[i], importantMaxValues[i]);
                    }
                    totalWeight += actionWeights[i];
                }
                if (totalWeight <= 0.0f)
                {
                    totalWeight = 1.0f;
                }

                // randomly sample proportional to weights
                float randVal     = Random.value;
                float cumulSum    = 0.0f;
                int   chosenThing = 0;
                for (int i = 0; i < (int)TypeOfThingDoing.MaxValue; i++)
                {
                    cumulSum += actionWeights[i] / totalWeight;
                    if (randVal <= cumulSum)
                    {
                        chosenThing = i;
                        break;
                    }
                }

                int   curAct       = (int)thingDoing.typeOfThing;
                float curWeight    = actionWeights[curAct];
                float chosenWeight = actionWeights[chosenThing];

                float diff = curWeight - chosenWeight;
                // if current is much more likely, don't change
                if (diff > 1.0f)
                {
                }
                // otherwise, change with diff pr (if diff < 0 this means always change)
                else/* if (diff < 0)
                     * {
                     * TypeOfThingDoing chosenThingDoing = (TypeOfThingDoing)chosenThing;
                     * thingDoing = UpdateBehavior(chosenThingDoing);
                     * if (thingDoing.typeOfThing == TypeOfThingDoing.GettingFood)
                     * {
                     *  OnSearchForFood(out lookingForBlock, out blockLookingFor);
                     * }
                     * }
                     * else if (Random.value < diff)*/
                {
                    TypeOfThingDoing chosenThingDoing = (TypeOfThingDoing)chosenThing;
                    ThingDoing       prevThingDoing   = thingDoing;
                    thingDoing = UpdateBehavior(chosenThingDoing);
                    if (thingDoing != prevThingDoing)
                    {
                        iNeedToPathfindAgain = true;
                    }
                    if (thingDoing.typeOfThing == TypeOfThingDoing.GettingFood)
                    {
                        OnSearchForFood(out lookingForBlock, out blockLookingFor);
                    }
                }
            }


            if (thingDoing.typeOfThing == TypeOfThingDoing.GettingFood || thingDoing.typeOfThing == TypeOfThingDoing.RunningAway || thingDoing.typeOfThing == TypeOfThingDoing.Gathering || thingDoing.typeOfThing == TypeOfThingDoing.GoingTo)
            {
                UpdatePathing();
            }
            else if (thingDoing.typeOfThing == TypeOfThingDoing.Socializing)
            {
                thingDoing.typeOfThing = TypeOfThingDoing.Wandering;
            }
            else if (thingDoing.typeOfThing == TypeOfThingDoing.Standing)
            {
                GetComponent <MovingEntity>().desiredMove = Vector3.zero;
            }
            else if (thingDoing.typeOfThing == TypeOfThingDoing.Wandering)
            {
                if (updateWander.Do())
                {
                    //int randVal = Random.Range(0, 5);
                    Vector3[]    options     = new Vector3[] { Vector3.zero, Vector3.forward, Vector3.right, Vector3.left, Vector3.back };
                    Vector3      desiredMove = options[Random.Range(0, options.Length)];
                    MovingEntity me          = GetComponent <MovingEntity>();
                    me.desiredMove = Vector3.zero;
                    me.jumping     = false;
                    RaycastResults blockStandingOn = me.BlockStandingOn();
                    if (blockStandingOn != null && desiredMove != Vector3.zero)
                    {
                        LVector3 myPos        = blockStandingOn.hitBlock + new LVector3(0, 1, 0);
                        LVector3 nextPos      = myPos + new LVector3((long)desiredMove.x, (long)desiredMove.y, (long)desiredMove.z);
                        LVector3 belowNextPos = nextPos + new LVector3(0, -1, 0);
                        LVector3 aboveNextPos = nextPos + new LVector3(0, 1, 0);

                        bool needsToJump  = false;
                        bool okayToMove   = false;
                        bool needsToShift = false;
                        // we need to hop up
                        if (nextPos.Block != Example.Air)
                        {
                            // we can hop up
                            if (aboveNextPos.Block == Example.Air)
                            {
                                okayToMove  = true;
                                needsToJump = true;
                            }
                            // we can't hop up
                            else
                            {
                            }
                        }
                        // we won't run into anything and can walk there
                        else
                        {
                            // going down
                            if (belowNextPos.Block == Example.Air)
                            {
                                LVector3 belowBelowNextPos = belowNextPos + new LVector3(0, -1, 0);
                                // too far to fall, don't do it
                                if (belowBelowNextPos.Block == Example.Air)
                                {
                                }
                                // down stairs, that's fine
                                else
                                {
                                    okayToMove = true;
                                }
                            }
                            // just horizontal, that's fine
                            else
                            {
                                okayToMove = true;
                            }
                        }


                        me.jumping    = needsToJump;
                        me.usingShift = needsToShift;
                        if (okayToMove)
                        {
                            me.desiredMove = desiredMove;
                        }
                    }
                }
            }
        }
Beispiel #6
0
        public void UpdatePathing()
        {
            ////// new temp stuff
            MovingEntity body = GetComponent <MovingEntity>();

            //pathingTarget = LVector3.FromUnityVector3(FindObjectOfType<BlocksPlayer>().transform.position);

            /*
             * // find position on ground below player and path to that instead
             * int goDownAmount = 10; // don't get into infinite loop, give up eventually
             * while (pathingTarget.BlockV == BlockValue.Air && goDownAmount > 0)
             * {
             *  pathingTarget = pathingTarget - new LVector3(0, 1, 0);
             *  goDownAmount--;
             * }
             * pathingTarget += new LVector3(0, 2, 0);
             */
            //////

            pathingTarget = LVector3.Invalid;

            if (thingDoing != null)
            {
                if (thingDoing.target != null)
                {
                    if (thingDoing.target.entity != null)
                    {
                        pathingTarget        = LVector3.FromUnityVector3(thingDoing.target.entity.transform.position);
                        iNeedToPathfindAgain = true;
                    }
                    else if (thingDoing.target.block != LVector3.Invalid)
                    {
                        pathingTarget = thingDoing.target.block;
                        //Debug.Log("going to pathing target with block in thing doing of " + pathingTarget);
                    }
                }
            }

            if (curPath == null)
            {
                iNeedToPathfindAgain = true;
            }

            if (pathingTarget == LVector3.Invalid)
            {
                body.desiredMove = Vector3.zero;
            }
            if (PhysicsUtils.millis() - lastPathfind > 1000.0 / pathfindsPerSecond && frameUpdatedLast != Time.frameCount && iNeedToPathfindAgain) // offset so everyone isn't aligned on the same frame
            {
                LVector3 myPos = LVector3.FromUnityVector3(transform.position);
                LVector3 foundThing;

                /*
                 * if (Search(out foundThing))
                 * {
                 *  // found it, is it closer?
                 *  if (pathingTarget == LVector3.Invalid || LVector3.CityBlockDistance(foundThing, myPos) < LVector3.CityBlockDistance(pathingTarget, myPos))
                 *  {
                 *      // if so, go to it instead
                 *      ThingDoing newThingDoing = new ThingDoing(thingDoing.typeOfThing, new ThingDoingTarget(foundThing));
                 *      // copy over valid blocks for future reference
                 *      if (thingDoing != null && thingDoing.target != null)
                 *      {
                 *          newThingDoing.target.validBlocks = thingDoing.target.validBlocks;
                 *      }
                 *      thingDoing = newThingDoing;
                 *      pathingTarget = foundThing;
                 *  }
                 *  //Debug.Log("found thing when looking");
                 * }
                 * else
                 * {
                 *  // did not find
                 *  //Debug.Log("did not find thing when looking");
                 *  //Debug.Log("did not find thing in " + steps + " steps");
                 * }
                 */
                frameUpdatedLast = Time.frameCount;
                //Debug.Log("updating pathing");
                RaycastResults blockStandingOn;

                bool lookingForBlocks = false;
                if (thingDoing != null && thingDoing.target != null && thingDoing.target.entity == null && thingDoing.target.block == LVector3.Invalid && thingDoing.target.validBlocks != null)
                {
                    lookingForBlocks = true;
                }

                if (pathingTarget != LVector3.Invalid || lookingForBlocks)
                {
                    if (PhysicsUtils.RayCastAlsoHitWater(body.transform.position, -Vector3.up, 20.0f, out blockStandingOn))
                    {
                        // if we are using shift and standing over an empty block, but our feet are on a neighboring block, use that neighboring block for pathfinding instead
                        if (blockStandingOn != LVector3.Invalid)
                        {
                            myPos = blockStandingOn.hitBlock + new LVector3(0, blocksHeight, 0);
                        }
                        //LVector3 playerPos = LVector3.FromUnityVector3(pathingTarget.transform.position);
                        bool iShouldJump;
                        if (thingDoing.typeOfThing == TypeOfThingDoing.RunningAway)
                        {
                            PhysicsUtils.PathfindAway(blocksHeight, ref curPath, out iShouldJump, myPos, pathingTarget, 100);
                        }
                        else
                        {
                            //// new stuff
                            bool             pathingSuccess = false;
                            PathingRegionPos resPath        = null;
                            if (lookingForBlocks)
                            {
                                resPath = PathingChunk.PathindToResource(World.mainWorld, myPos, GetComponent <MovingEntity>().reachRange, thingDoing.target.validBlocks, new MobilityCriteria(1, 1, blocksHeight, 1), out pathingSuccess, out blockWeCanSeeOnceWeGetThere, verbose: world.blocksWorld.verbosePathing);
                                if (resPath != null)
                                {
                                    pathingTarget = new LVector3(resPath.wx, resPath.wy, resPath.wz);
                                    thingDoing    = new ThingDoing(thingDoing.typeOfThing, new ThingDoingTarget(pathingTarget, thingDoing.target.validBlocks));
                                }
                            }
                            else
                            {
                                resPath = BlocksPathing.Pathfind(World.mainWorld, myPos, pathingTarget, 1, 1, blocksHeight, 1, out pathingSuccess, verbose: false);
                            }
                            iShouldJump = false;
                            if (resPath != null)
                            {
                                curPath = (new PathingResult(resPath)).GetPathNode();

                                iNeedToPathfindAgain = false;

                                //Debug.Log("got path with next pos " + curPath.pos + " also, my pos is " + myPos + " and pathing target is " + pathingTarget);
                                if (curPath.nextNode != null && curPath.nextNode.pos.y > curPath.pos.y)
                                {
                                    iShouldJump = true;
                                }

                                if (curPath.nextNode != null)
                                {
                                    //curPath = curPath.nextNode;
                                }
                            }
                            else
                            {
                                curPath = null;
                                iNeedToPathfindAgain = true;
                            }


                            /////
                            ///

                            // old thing:
                            //PhysicsUtils.Pathfind(blocksHeight, ref curPath, out iShouldJump, myPos, pathingTarget+new LVector3(0,1,0), 100);
                        }
                        if (curPath != null)
                        {
                            if (curPath.nextNode == null)
                            {
                                //Debug.Log("curPath = " + curPath.pos + " myPos = " + myPos + " next null");
                            }
                            else
                            {
                                //Debug.Log("curPath = " + curPath.pos + " myPos = " + myPos + " nextPath = " + curPath.nextNode.pos);
                            }
                        }
                        if (iShouldJump)
                        {
                            body.jumping = true;
                        }
                    }
                    else
                    {
                        //Debug.Log("falling far, cannot pathfind");
                    }
                }
                lastPathfind = PhysicsUtils.millis();
            }


            if (pathingTarget == LVector3.Invalid)
            {
                //Debug.Log("has invalid pathing target?");
                iNeedToPathfindAgain = true;
            }
            body.desiredMove = Vector3.zero;
            Vector3 targetPos = transform.position;

            if (curPath != null && pathingTarget != LVector3.Invalid)
            {
                /* // dani commented this out recently
                 * LVector3 myPos = LVector3.FromUnityVector3(transform.position);
                 * RaycastResults blockStandingOn;
                 * if (PhysicsUtils.RayCastAlsoHitWater(body.transform.position, -Vector3.up, 20.0f, out blockStandingOn))
                 * {
                 *  // if we are using shift and standing over an empty block, but our feet are on a neighboring block, use that neighboring block for pathfinding instead
                 * myPos = blockStandingOn.hitBlock + new LVector3(0, blocksHeight, 0);
                 * }
                 * LVector3 myPosBeforeJump = myPos - new LVector3(0, 1, 0);
                 * LVector3 myPosBeforeFall = myPos + new LVector3(0, 1, 0);
                 */



                //if (curPath.prevNode != null && (myPos == curPath.prevNode.pos || myPosBeforeJump == curPath.prevNode.pos))
                //{

                //}
                //else

                /*
                 * PathNode closest = curPath;
                 * float closestDist = LVector3.EuclideanDistance(closest.pos, myPos);
                 * PathNode curTmp = closest;
                 * while(curTmp.prevNode != null)
                 * {
                 *  curTmp = curTmp.prevNode;
                 *  float tmpDist = LVector3.EuclideanDistance(curTmp.pos, myPos);
                 *  if (tmpDist < closestDist)
                 *  {
                 *      closest = curTmp;
                 *      closestDist = tmpDist;
                 *  }
                 * }
                 * curTmp = curPath;
                 * while (curTmp.nextNode != null)
                 * {
                 *  curTmp = curTmp.nextNode;
                 *  float tmpDist = LVector3.EuclideanDistance(curTmp.pos, myPos);
                 *  if (tmpDist < closestDist)
                 *  {
                 *      closest = curTmp;
                 *      closestDist = tmpDist;
                 *  }
                 * }
                 *
                 * if (closest.pos == myPos)
                 * {
                 *  if (closest.nextNode == null)
                 *  {
                 *      Debug.Log("reached end of path");
                 *  }
                 *  else
                 *  {
                 *      curPath = closest.nextNode;
                 *  }
                 * }
                 * else
                 * {
                 *  curPath = closest;
                 * }*/


                /* // dani commented this out recently
                 * if (curPath.nextNode != null && (myPos == curPath.nextNode.pos || myPosBeforeJump == curPath.nextNode.pos || myPosBeforeFall == curPath.nextNode.pos))
                 * {
                 *  curPath = curPath.nextNode;
                 * }
                 * else if (myPos == curPath.pos || myPosBeforeJump == curPath.pos || myPosBeforeFall == curPath.pos)
                 * {
                 *  if (curPath.nextNode != null)
                 *  {
                 *      curPath = curPath.nextNode;
                 *  }
                 * }
                 *
                 *
                 * LVector3 targetBlock = curPath.pos;
                 * if (targetBlock.y == LVector3.FromUnityVector3(transform.position).y)
                 * {
                 *  //body.usingShift = true;
                 *  body.usingShift = false;
                 * }
                 * else
                 * {
                 *  body.usingShift = false;
                 * }
                 * if (targetBlock.y > myPos.y)
                 * {
                 *  body.jumping = true;
                 * }
                 * else
                 * {
                 *  body.jumping = false;
                 * }
                 * targetPos = targetBlock.BlockCentertoUnityVector3();
                 * body.SetAbsoluteDesiredMove((targetPos - transform.position).normalized);
                 */


                Vector3 dirToMove;
                bool    pushedOffPath;
                curPath = curPath.GetCurNode(transform.position, out body.jumping, out dirToMove, out pushedOffPath);
                body.SetAbsoluteDesiredMove(dirToMove);

                if (pushedOffPath)
                {
                    //Debug.Log("pushed off path");
                    //iNeedToPathfindAgain = true;
                }

                if (curPath.nextNode != null)
                {
                    //Debug.Log("got cur path " + curPath.pos + " with jumping " + body.jumping + " and dir to move " + dirToMove + " and next " + curPath.nextNode.pos + " and pushed off path " + pushedOffPath);
                }
                else
                {
                    //Debug.Log("got cur path " + curPath.pos + " with jumping " + body.jumping + " and dir to move " + dirToMove + " and no next and pushed off path " + pushedOffPath);
                }


                BlockValue blockWeAreGoingTo = blockWeCanSeeOnceWeGetThere.BlockV;

                if (!DesiredBlock(blockWeAreGoingTo) && thingDoing != null && thingDoing.target != null && thingDoing.target.entity == null)
                {
                    Debug.Log("rip someone took my block , my block is now " + World.BlockToString(blockWeAreGoingTo));
                    curPath       = null;
                    pathingTarget = LVector3.Invalid;
                }
                else
                {
                    float myDist = LVector3.CityBlockDistance(LVector3.FromUnityVector3(transform.position), pathingTarget);
                    // found it, eat it
                    if (myDist <= 2)
                    {
                        //Debug.Log("got to desired block");
                        if (thingDoing != null && thingDoing.typeOfThing == TypeOfThingDoing.GettingFood)
                        {
                            OnReachFoodBlock(blockWeCanSeeOnceWeGetThere);
                        }
                        else if (thingDoing != null && thingDoing.typeOfThing == TypeOfThingDoing.Gathering)
                        {
                            OnReachBlockToGather(blockWeCanSeeOnceWeGetThere);
                        }

                        /*
                         * DidEatObject(pathingTarget, 1.0f);
                         * world[pathingTarget] = (int)Example.Flower;
                         */
                        //this.thingDoing = new ThingDoing(TypeOfThingDoing.GettingFood, null);
                        if (thingDoing != null && thingDoing.target != null)
                        {
                            this.thingDoing = new ThingDoing(thingDoing.typeOfThing, new ThingDoingTarget(thingDoing.target.validBlocks));
                        }
                        else if (thingDoing != null)
                        {
                            this.thingDoing = new ThingDoing(thingDoing.typeOfThing, null);
                        }
                        curPath              = null;
                        pathingTarget        = LVector3.Invalid;
                        body.jumping         = false;
                        iNeedToPathfindAgain = true;
                    }
                    // still pathing to it
                    else
                    {
                    }
                }
            }
        }
Beispiel #7
0
 public ThingDoingTarget(MovingEntity entity)
 {
     this.entity = entity;
     this.block  = LVector3.Invalid;
 }