King Abilities/Radial Menu bugfixes

>Radial Menu has been bugfixed so the players have a harder time
breaking things
>King abilities have had some repeated code moved into a seperate class
This commit is contained in:
Katherine 2022-02-23 13:18:54 -06:00
parent de49e97f3f
commit 0655b86352
6 changed files with 192 additions and 164 deletions

View File

@ -14376,6 +14376,11 @@ MeshCollider:
m_Convex: 0
m_CookingOptions: 30
m_Mesh: {fileID: 1626541045562377096, guid: 50a1c343e2b03d94b949098ca0255428, type: 3}
--- !u!1 &540093853 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 8183403963968820413, guid: d23bf55f2a40d494487eb188930f895d, type: 3}
m_PrefabInstance: {fileID: 8183403963536638187}
m_PrefabAsset: {fileID: 0}
--- !u!1 &542093930
GameObject:
m_ObjectHideFlags: 0
@ -50272,6 +50277,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: d94be097208c22f4daa3776bd00128b4, type: 3}
m_Name:
m_EditorClassIdentifier:
King: {fileID: 540093853}
--- !u!1 &1885653570
GameObject:
m_ObjectHideFlags: 0
@ -61870,6 +61876,14 @@ PrefabInstance:
propertyPath: m_Enabled
value: 1
objectReference: {fileID: 0}
- target: {fileID: 8183403964692436335, guid: d23bf55f2a40d494487eb188930f895d, type: 3}
propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_Mode
value: 3
objectReference: {fileID: 0}
- target: {fileID: 8183403964692436335, guid: d23bf55f2a40d494487eb188930f895d, type: 3}
propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_MethodName
value: PlaceObject
objectReference: {fileID: 0}
- target: {fileID: 8183403965069105119, guid: d23bf55f2a40d494487eb188930f895d, type: 3}
propertyPath: m_Text
value: Thunder
@ -61882,6 +61896,18 @@ PrefabInstance:
propertyPath: m_FontData.m_FontSize
value: 10
objectReference: {fileID: 0}
- target: {fileID: 8183403965182652613, guid: d23bf55f2a40d494487eb188930f895d, type: 3}
propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_Mode
value: 3
objectReference: {fileID: 0}
- target: {fileID: 8183403965182652613, guid: d23bf55f2a40d494487eb188930f895d, type: 3}
propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_MethodName
value: PlaceObject
objectReference: {fileID: 0}
- target: {fileID: 8183403965182652613, guid: d23bf55f2a40d494487eb188930f895d, type: 3}
propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_Arguments.m_IntArgument
value: 1
objectReference: {fileID: 0}
- target: {fileID: 8183403965182652614, guid: d23bf55f2a40d494487eb188930f895d, type: 3}
propertyPath: m_SizeDelta.x
value: 45
@ -61930,6 +61956,18 @@ PrefabInstance:
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8183403965183742975, guid: d23bf55f2a40d494487eb188930f895d, type: 3}
propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_Mode
value: 3
objectReference: {fileID: 0}
- target: {fileID: 8183403965183742975, guid: d23bf55f2a40d494487eb188930f895d, type: 3}
propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_MethodName
value: PlaceObject
objectReference: {fileID: 0}
- target: {fileID: 8183403965183742975, guid: d23bf55f2a40d494487eb188930f895d, type: 3}
propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_Arguments.m_IntArgument
value: 2
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: d23bf55f2a40d494487eb188930f895d, type: 3}
--- !u!143 &8445875816224330693

View File

@ -0,0 +1,53 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class KingAbility
{
public int CooldownTimer;
private int CooldownLength;
private int FramestoSeconds = 0;
private bool Avaliable = true;
private int EnergyCost;
public KingAbility() {
CooldownLength = 3;
CooldownTimer = CooldownLength;
EnergyCost = 20;
}
public KingAbility(int cooldown, int energy) {
CooldownLength = cooldown;
CooldownTimer = CooldownLength;
EnergyCost = energy;
}
public void Cooldown() {
if (Avaliable == false) {
FramestoSeconds++;
if (FramestoSeconds == 50) {
FramestoSeconds = 0;
CooldownTimer--;
if (CooldownTimer == 0) {
CooldownTimer = CooldownLength;
Avaliable = true;
}
}
}
}
public void UseItem() {
Avaliable = false;
}
public bool IsAvaliable() {
return Avaliable;
}
public int Energy() {
return EnergyCost;
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 37c7903e800c77e4fa70154574ae865a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -8,6 +8,8 @@ public class KingMove : MonoBehaviour
private Vector3 newPos;
private Vector3 MountCent = new Vector3(-4500, 620, 510);
private Vector3 KingStrPos = new Vector3(350, 625, 1130);
private Vector3 KingMontStr = new Vector3(-4500, 625, 1130);
private GameObject Grid;
void Awake()
@ -35,30 +37,30 @@ public class KingMove : MonoBehaviour
translation *= Time.deltaTime;
// Move translation along the object's z-axis
if (transform.position.x <= 350 && transform.position.x >= -4500) {
if (transform.position.x <= KingStrPos.x && transform.position.x >= KingMontStr.x) {
transform.Translate(translation, 0, 0);
Grid.GetComponent<GridReveal>().DynGridReveal(transform.position.x, translation); //Makes the grid reveal itself as the King moves
transform.rotation = Quaternion.Euler(0, 180, 0);
}
else if (transform.position.x > 350) {
transform.position = new Vector3(350, 625, 1130);//Keeps them from going too far left
else if (transform.position.x > KingStrPos.x) {
transform.position = KingStrPos;//Keeps them from going too far left
}
else if (transform.position.x < -4500) {//Once they rech a certain point they begin to cirlce around the mountain (radius of 1050, (x+4500)^2+(z-510)^2=620^2)
else if (transform.position.x < KingMontStr.x) {//Once they rech a certain point they begin to cirlce around the mountain (radius of 1050, (x+4500)^2+(z-510)^2=620^2)
float z = transform.position.z;
z -= translation; //Moves the player's X forward slightly
if (z > -110 && z <= 1130) { //Stops this from breaking the circle's formula
float x = -Mathf.Sqrt((620 * 620) - ((z - 510) * (z - 510))) - 4500; //Snaps the player onto a circle that is around the mountain, so the player orbits it smoothly
if (z > -110 && z <= KingMontStr.z) { //Stops this from breaking the circle's formula
float x = -Mathf.Sqrt((MountCent.y * MountCent.y) - ((z - MountCent.z) * (z - MountCent.z))) + MountCent.x; //Snaps the player onto a circle that is around the mountain, so the player orbits it smoothly
newPos = new Vector3(x, 625, z); //make a Vector3 out of the new X and Z
transform.position = newPos;//Sets the player's new position on the cirlce
transform.LookAt(MountCent);//Rotates the player as they move along the circumfurance
}
if (z > 1130) {//Snaps the player back onto the horizontal track
transform.position = new Vector3(-4500, 625, 1130);
if (z > KingMontStr.z) {//Snaps the player back onto the horizontal track
transform.position = KingMontStr;
}
}
else {//If somehow the player disappears into the void, resets them
Debug.Log("Aw, Beans");
transform.position = new Vector3(350, 625, 1130);
transform.position = KingStrPos;
}
}
}

View File

@ -7,49 +7,6 @@ using UnityEngine;
public class KingPlace : NetworkBehaviour
{
private bool BoxAvaliable = true;
private int BoxCool = 3;
private bool HailAvaliable = true;
private int HailCool = 3;
private bool SlimeAvaliable = true;
private int SlimeCool = 3;
private bool ThundAvaliable = true;
private int ThundCool = 3;
//Is called when the King clicks on the Block button
public void OnBlockClicked() {
if (BoxAvaliable) {
PlaceObject(0);
MenuOff();
}
}
//Is called when the King clicks on the Hail button
public void OnHailClicked() {
if (HailAvaliable) {
PlaceObject(1);
MenuOff();
}
}
//Is called when the King clicks on the Slime button
public void OnSlimeClicked() {
if (SlimeAvaliable) {
PlaceObject(2);
MenuOff();
}
}
public GameObject Thunderstorm;
//Is called when the King clicks on the Thunderstorm button
public void OnThunderClicked() {
if (ThundAvaliable) {
//TODO thunderstorm
Cooldown(3);
MenuOff();
}
}
public GameObject Block;
public GameObject BlockWithoutNetwork;
@ -61,12 +18,30 @@ public class KingPlace : NetworkBehaviour
private GameObject Place;
private GameObject PlaceTemp = null;
private GameObject HailCorner;
private int SlimeDir;
private bool FirstPlacing = false;
public bool FirstPlacing = false;
private bool HailPlacing = false;
private bool SlimePlacing = false;
private int SlimeDir;
private int BoxSize = 20;
private KingAbility KABlock = new KingAbility(1, 5);
private KingAbility KASlime = new KingAbility(1, 15);
private KingAbility KAHail = new KingAbility(1, 15);
private KingAbility KAThund = new KingAbility(1, 10);
public GameObject Thunderstorm;
//Is called when the King clicks on the Thunderstorm button
public void OnThunderClicked()
{
if (KAThund.IsAvaliable()) {
//TODO thunderstorm
KAThund.UseItem();
MenuOff();
}
}
private int Energy = 100;
private GameObject boxPlaced;
@ -76,20 +51,26 @@ public class KingPlace : NetworkBehaviour
Grid = GameObject.FindGameObjectWithTag("KingGrid");
}
private void PlaceObject(int ID) {
//Switch statement, ID-0 = Block,ID-1 = Hail,ID-2 = Slime
switch (ID)
{//Parses in the button clicked into the right object that the King is placing
case 0:
Place = BlockWithoutNetwork;
break;
case 1:
Place = HailSprite;
break;
case 2:
Place = Slime;
break;
}
bool Avaliable;
public void PlaceObject(int ID) { //Is called when trhe King clicks the Block,Hail,or Slime button
//Switch statement, ID-0 = Block,ID-1 = Hail,ID-2 = Slime
Avaliable = false;
switch (ID) {//Parses in the button clicked into the right object that the King is placing
case 0:
Place = BlockWithoutNetwork;
Avaliable = KABlock.IsAvaliable();
break;
case 1:
Place = HailSprite;
Avaliable = KAHail.IsAvaliable();
break;
case 2:
Place = Slime;
Avaliable = KASlime.IsAvaliable();
break;
}
if (Avaliable == true) {
MenuOff();
//Create the object that will follow the Mouse
PlaceTemp = Instantiate(Place);
//Layout the grid
@ -97,6 +78,7 @@ public class KingPlace : NetworkBehaviour
//The player can then see where the object will be placed, reletive to the Grid
FirstPlacing = true;
}
}
private void MenuOff() {
@ -115,21 +97,18 @@ public class KingPlace : NetworkBehaviour
if (Input.GetMouseButtonDown(0)) {//Reads the player clicking the left mouse button
FindGridBox();
}
if (Input.GetMouseButtonUp(1)) {//Allows the player to cancel out a button press
Destroy(PlaceTemp);
Grid.GetComponent<GridReveal>().GridSwitch(false);
FirstPlacing = false;
if (Input.GetMouseButtonUp(1)) {//Reads the player pressing the right mouse button
CancelPlacing();
}
}
if (HailPlacing == true) {
Ray Ray = KingCam.ScreenPointToRay(Input.mousePosition);//Raycast to find the point where the mouse cursor is
if (Physics.Raycast(Ray, out RaycastHit RayCastHit, float.MaxValue, LayerMask))
{
if (Physics.Raycast(Ray, out RaycastHit RayCastHit, float.MaxValue, LayerMask)) {
HailCorner.transform.position = RayCastHit.point;
}
if (Input.GetMouseButtonUp(0)) {//Reads the player releasing the left mouse button
CreateHail();
Cooldown(1);
KAHail.UseItem();
}
}
if (SlimePlacing == true) {
@ -137,52 +116,56 @@ public class KingPlace : NetworkBehaviour
if (Input.GetMouseButtonUp(0)) {//Reads the player releasing the left mouse button
PlaceTemp.GetComponent<Slime>().GooStart(SlimeDir);
SlimePlacing = false;
Cooldown(2);
KASlime.UseItem();
}
}
}
public void CancelPlacing() {//Allows the player to cancel out a button press
Destroy(PlaceTemp);
Grid.GetComponent<GridReveal>().GridSwitch(false);
FirstPlacing = false;
}
private void FixedUpdate() {
CooldownTimer();
EnergyRefill();
}
int xOffset = 101;
int zOffset = 906;
private GameObject Row;
private void FindGridBox() {
float i = ((PlaceTemp.transform.position.x) - 101) / -BoxSize; //Finds the Row the cursor is in
float i = ((PlaceTemp.transform.position.x) - xOffset) / -BoxSize; //Finds the Row the cursor is in
int RowNumb = (int)i; //Rounds it down
float y = ((PlaceTemp.transform.position.z) - 906) / -BoxSize; //Finds the Box in the Row the cursor is in
float y = ((PlaceTemp.transform.position.z) - zOffset) / -BoxSize; //Finds the Box in the Row the cursor is in
int Box = (int)y; //Rounds it down
int x = (RowNumb * -BoxSize) + 101;//Sets it's X to the X of the Row
int z = (Box * -BoxSize) + 906;//Sets its Z to the Z of the Box
int x = (RowNumb * -BoxSize) + xOffset;//Sets it's X to the X of the Row
int z = (Box * -BoxSize) + zOffset;//Sets its Z to the Z of the Box
// Grid Check first for valid location
GridCheck(RowNumb, Box, ref FirstPlacing);//Makes sure the Box is a valid position
// Instantiate a networked box at the position
if (FirstPlacing == false)
{
if (FirstPlacing == false) {
// Calculate the position to spawn at
Vector3 spawnLoc = new Vector3(x, PlaceTemp.transform.position.y, z);
PlaceTemp.transform.position = spawnLoc;
if (Place == BlockWithoutNetwork)
{
if (Place == BlockWithoutNetwork) {
// Have the server spawn the box
SpawnBoxServerRPC(spawnLoc);
// Remove the reference to PlaceTemp
Destroy(PlaceTemp);
Cooldown(0);
KABlock.UseItem();
}
if (Place == Slime)
{//If Object is Hail or Slime set the respective Placing value to true so it can launch into the secondary placing function
if (Place == Slime) {//If Object is Hail or Slime set the respective Placing value to true so it can launch into the secondary placing function
SlimePlacing = true;
}
else if (Place == HailSprite)
{
else if (Place == HailSprite) {
Grid.GetComponent<GridReveal>().GridSwitch(true);
HailPlacing = true;
HailCorner = Instantiate(Place);
@ -213,12 +196,12 @@ public class KingPlace : NetworkBehaviour
}
private void CreateHail() {//TODO make sure it makes a box/actually make the Hail Area
float i = ((HailCorner.transform.position.x) - 101) / -BoxSize; //Finds the Row the cursor is in
float i = ((HailCorner.transform.position.x) - xOffset) / -BoxSize; //Finds the Row the cursor is in
int RowNumb = (int)i; //Rounds it down
float y = ((HailCorner.transform.position.z) - 906) / -BoxSize; //Finds the Box in the Row the cursor is in
float y = ((HailCorner.transform.position.z) - zOffset) / -BoxSize; //Finds the Box in the Row the cursor is in
int Box = (int)y; //Rounds it down
int x = (RowNumb * -BoxSize) + 101;//Sets it's X to the X of the Row
int z = (Box * -BoxSize) + 906;//Sets its Z to the Z of the Box
int x = (RowNumb * -BoxSize) + xOffset;//Sets it's X to the X of the Row
int z = (Box * -BoxSize) + zOffset;//Sets its Z to the Z of the Box
HailCorner.transform.position = new Vector3(x, HailCorner.transform.position.y, z);//fully snaps it to the grid
GridCheck(RowNumb, Box, ref HailPlacing);//Makes sure the Box is a valid position
//Instanciate HailArea based on PlaceTemp = Top Left and HailCorner = Bottom Right
@ -253,80 +236,18 @@ public class KingPlace : NetworkBehaviour
else {
return 2;//Defaults to down, just in case
}
}
private void Cooldown(int ID) {
switch (ID) {//Parses in the button clicked into the right object that the King is placing
case 0:
BoxAvaliable = false;//Block Cooldown
break;
case 1:
HailAvaliable = false;//Hail Cooldown
break;
case 2:
SlimeAvaliable = false;//Slime Cooldown
break;
case 3:
ThundAvaliable = false;//Thunderstorm Cooldown
break;
}
}
private int BSC = 0;
private int HSC = 0;
private int SSC = 0;
private int TSC = 0;
}
private void CooldownTimer() {// Function for tracking the individual cooldowns of the items. It's done in a two-teired system to allow the cooldowns to be eaisly converted as seconds
if(BoxAvaliable == false) {
BSC++;
if (BSC == 50) {
BSC = 0;
BoxCool--;
if (BoxCool == 0) {
BoxCool = 3;
BoxAvaliable = true;
}
}
}
if (HailAvaliable == false) {
HSC++;
if (HSC == 50) {
HSC = 0;
HailCool--;
if (HailCool == 0) {
HailCool = 3;
HailAvaliable = true;
}
}
}
if (SlimeAvaliable == false) {
SSC++;
if (SSC == 50) {
SSC = 0;
SlimeCool--;
if (SlimeCool == 0) {
SlimeCool = 3;
SlimeAvaliable = true;
}
}
}
if (ThundAvaliable == false) {
TSC++;
if (TSC == 50) {
TSC = 0;
ThundCool--;
if (ThundCool == 0) {
ThundCool = 3;
ThundAvaliable = true;
}
}
}
KABlock.Cooldown();
KAHail.Cooldown();
KASlime.Cooldown();
KAThund.Cooldown();
}
private bool SpendEnergy(int cost) {
if (Energy > cost) {
Energy -= cost;
private bool SpendEnergy(KingAbility Ability) {
if (Energy > Ability.Energy()) {
Energy -= Ability.Energy();
return true;
}
else {

View File

@ -6,6 +6,7 @@ public class RadialMenu : MonoBehaviour
{
bool UIOn = false;
public GameObject King;
// Update is called once per frame
void Update()
{
@ -13,7 +14,9 @@ public class RadialMenu : MonoBehaviour
transform.position = Input.mousePosition;//Moved the UI to where the mouse is
}
if(Input.GetAxis("RadialMenu") > 0) {//Pressing Q makes the UI appear
//Stop placing if already placing
if (King.GetComponent<KingPlace>().FirstPlacing == true) {
King.GetComponent<KingPlace>().CancelPlacing();
}
MenuOn();
}
if (Input.GetAxis("RadialMenu") < 0) {//Pressing E makes the UI dissapear