/* * public override void UpdateBehavior(ref ThingDoing curDoing) * { * * if (curDoing == null) * { * curDoing = new ThingDoing(TypeOfThingDoing.Searching, null); * } * * if (food < wantToFindFoodThresh && curDoing.typeOfThing != TypeOfThingDoing.Chasing && curDoing.typeOfThing != TypeOfThingDoing.Searching) * { * curDoing = new ThingDoing(TypeOfThingDoing.Searching); * } * * if (food >= wantToFindFoodThresh && curDoing.typeOfThing != TypeOfThingDoing.RunningAway) * { * curDoing = new ThingDoing(TypeOfThingDoing.Standing); * } * * * BlocksPlayer[] players = FindObjectsOfType<BlocksPlayer>(); * * foreach (BlocksPlayer player in players) * { * if (Vector3.Distance(player.transform.position, transform.position) < 10.0f) * { * curDoing = new ThingDoing(TypeOfThingDoing.RunningAway, new ThingDoingTarget(player.GetComponent<MovingEntity>())); * } * } * * MovingEntity self = GetComponent<MovingEntity>(); * if (curDoing.typeOfThing == TypeOfThingDoing.Chasing) * { * if (curDoing.target.entity == null) * { * pathingTarget = curDoing.target.block; * } * else * { * pathingTarget = LVector3.FromUnityVector3(curDoing.target.entity.transform.position); * } * * * if (pathingTarget.BlockV != Example.FlowerWithNectar) * { * curDoing = new ThingDoing(TypeOfThingDoing.Searching, null); * } * else * { * float myDist = LVector3.CityBlockDistance(LVector3.FromUnityVector3(transform.position), pathingTarget); * // found it, eat it * if (myDist < 4) * { * DidEatObject(pathingTarget, 1.0f); * world[pathingTarget] = (int)Example.Flower; * curDoing = new ThingDoing(TypeOfThingDoing.Searching, null); * } * // still pathing to it * else * { * UpdatePathing(); * } * } * //pathingTarget = LVector3.FromUnityVector3(FindObjectOfType<BlocksPlayer>().transform.position); * } * else if (curDoing.typeOfThing == TypeOfThingDoing.RunningAway) * { * if (curDoing.target.entity == null) * { * pathingTarget = curDoing.target.block; * } * else * { * pathingTarget = LVector3.FromUnityVector3(curDoing.target.entity.transform.position); * } * } * else if (curDoing.typeOfThing == TypeOfThingDoing.Searching) * { * } * else if (curDoing.typeOfThing == TypeOfThingDoing.Sitting) * { * * } * else if (curDoing.typeOfThing == TypeOfThingDoing.Socializing) * { * * } * else if (curDoing.typeOfThing == TypeOfThingDoing.Standing) * { * GetComponent<CrocodileDoggy>().SetSpeed(0.0f); * self.desiredMove = Vector3.zero; * } * else if (curDoing.typeOfThing == TypeOfThingDoing.Wandering) * { * * } * } * */ public override ThingDoing UpdateBehavior(TypeOfThingDoing newTypeOfThingDoing) { ThingDoing result = null; if (assignment == SisterAssignment.StayWithMother) { result = new ThingDoing(TypeOfThingDoing.GoingTo, new ThingDoingTarget(mother.GetComponent <MovingEntity>())); } else if (assignment == SisterAssignment.StayWithChampion) { result = new ThingDoing(TypeOfThingDoing.GoingTo, new ThingDoingTarget(champion.GetComponent <MovingEntity>())); } else if (assignment == SisterAssignment.Forage) { result = new ThingDoing(TypeOfThingDoing.Gathering, new ThingDoingTarget(new BlockValue[] { Example.Leaf, Example.Trunk, Example.Flower })); } else if (assignment == SisterAssignment.KeepWatch) { result = new ThingDoing(TypeOfThingDoing.Standing, null); } else { Debug.LogWarning("unknown sister assignment " + assignment); result = new ThingDoing(newTypeOfThingDoing, null); } if (result.typeOfThing == thingDoing.typeOfThing) { // don't modify it if valid blocks matches (this keeps a found position if there is one when foraging) if (result.target != null && result.target.validBlocks != null) { if (thingDoing.target == null || thingDoing.target.validBlocks == null || thingDoing.target.validBlocks.Length != result.target.validBlocks.Length) { return(result); } else { for (int i = 0; i < result.target.validBlocks.Length; i++) { if (thingDoing.target.validBlocks[i] != result.target.validBlocks[i]) { return(result); } } return(thingDoing); } } return(thingDoing); } else { return(result); } }
void ThrowStuff() { //for (int i = 0; i < playerUsing.blocksHoldingWithMouse.count; i++) { BlockEntity worldEntity = World.mainWorld.CreateBlockEntity(playerUsing.blocksHoldingWithMouse, transform.position + transform.forward * 1.0f); worldEntity.timeThrown = Time.time; worldEntity.GetComponent <MovingEntity>().SetAbsoluteDesiredMove(playerUsing.transform.forward); worldEntity.playerThrowing = playerUsing.GetComponent <MovingEntity>(); //Debug.Log(playerUsing.transform.forward); } CallInventoryModifiedCallbacks(); playerUsing.blocksHoldingWithMouse = new BlockStack(BlockValue.Air, 0); if (playerUsing.holdingWithMouseEntity != null) { GameObject.Destroy(playerUsing.holdingWithMouseEntity.gameObject); playerUsing.holdingWithMouseEntity = null; } }
// Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.Escape)) { paused = true; ShowPauseMenu(); } if (paused) { allowedToCapture = false; if (smoothMouseLook != null) { smoothMouseLook.allowedToCapture = allowedToCapture; } return; } if (!showingInventory) { showingBlockInventory = false; } if (showingInventory) { allowedToCapture = false; } else if (!paused) { allowedToCapture = true; } if (smoothMouseLook != null) { smoothMouseLook.allowedToCapture = allowedToCapture; } curMenuStatus = CurrentMenu; // in world if (blocksWorld != null && smoothMouseLook != null) { // if the current gui player is disabled, we need to search for which one we are actually using if (activeGuiPlayer == null || !activeGuiPlayer.enabled) { activeGuiPlayer = null; foreach (BlocksPlayer player in FindObjectsOfType <BlocksPlayer>()) { if (player.enabled) { activeGuiPlayer = player; break; } } if (activeGuiPlayer != null) { smoothMouseLook = activeGuiPlayer.GetComponent <SmoothMouseLook>(); } } if (curMenu == MenuStatus.LoadWorld || curMenu == MenuStatus.GenerateWorld || curMenu == MenuStatus.MainMenu) { curMenu = MenuStatus.Hotbar; showingInventory = false; showingBlockInventory = false; paused = false; } if (curMenuStatus != MenuStatus.BlockInventory && curMenuStatus != MenuStatus.Inventory) { if (playerInventoryShowing != null) { playerInventoryShowing.inventoryGui.displaying = false; playerInventoryShowing = null; } if (blockShowing != LVector3.Invalid || blockShowingInventory != null) { blocksWorld.otherObjectInventoryGui.displaying = false; blocksWorld.otherObjectInventoryGui.playerUsing = null; blocksWorld.otherObjectInventoryGui.inventory = null; blockShowingInventory = null; blockShowing = LVector3.Invalid; } } if (curMenuStatus == MenuStatus.Inventory) { if (playerInventoryShowing == null) { blocksWorld.otherObjectInventoryGui.displaying = false; blocksWorld.otherObjectInventoryGui.playerUsing = null; } } if (curMenuStatus == MenuStatus.Hotbar) { playerHotbarShowing = activeGuiPlayer; playerHotbarShowing.inventoryGui.numRows = 1; playerHotbarShowing.inventoryGui.inventory = playerHotbarShowing.inventory; playerHotbarShowing.inventoryGui.maxItems = playerHotbarShowing.hotbarSize; playerHotbarShowing.inventoryGui.screenOffset.y = -Screen.height / 2.0f + 100.0f; playerHotbarShowing.inventoryGui.displaying = true; } else { if (playerHotbarShowing != null) { //playerHotbarShowing.inventoryGui.displaying = false; //playerHotbarShowing = null; } } } // in main menu else { if (curMenuStatus == MenuStatus.Hotbar || curMenuStatus == MenuStatus.Inventory || curMenuStatus == MenuStatus.BlockInventory) { curMenu = MenuStatus.MainMenu; } } if (CurrentMenu == MenuStatus.Hotbar) { HideAllMenus(); } }