oct
This commit is contained in:
BIN
Assets/Script/.DS_Store
vendored
BIN
Assets/Script/.DS_Store
vendored
Binary file not shown.
13
Assets/Script/CharacterDataSO.cs
Normal file
13
Assets/Script/CharacterDataSO.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
[CreateAssetMenu(fileName = "Data", menuName = "ScriptableObjects/CharacterData", order = 1)]
|
||||
public class CharacterDataSO : ScriptableObject
|
||||
{
|
||||
public string jsonCharData;
|
||||
public string charName;
|
||||
|
||||
|
||||
}
|
||||
11
Assets/Script/CharacterDataSO.cs.meta
Normal file
11
Assets/Script/CharacterDataSO.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2b7d6ca0a7bac48388c4c141a7548d78
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -8,8 +8,8 @@ using UnityEngine.UI;
|
||||
public class CharacterSelection : MonoBehaviour
|
||||
{
|
||||
|
||||
public static string selectedCharJson = "";
|
||||
public List<string> predefinedCharacterJsons;
|
||||
[SerializeField] public static string selectedCharJson = "";
|
||||
public List<CharacterDataSO> predefinedCharacterJsons;
|
||||
public List<Button> predefinedCharacterButtons;
|
||||
|
||||
public static Action OnCharacterChanged;
|
||||
@@ -28,13 +28,13 @@ public class CharacterSelection : MonoBehaviour
|
||||
public void LoadCharacterFromString(string characterData)
|
||||
{
|
||||
selectedCharJson = characterData;
|
||||
OnCharacterChanged.Invoke();
|
||||
OnCharacterChanged?.Invoke();
|
||||
}
|
||||
|
||||
void OnPredefinedCharButtonPress(int i)
|
||||
{
|
||||
selectedCharJson = predefinedCharacterJsons[i];
|
||||
OnCharacterChanged.Invoke();
|
||||
selectedCharJson = predefinedCharacterJsons[i].jsonCharData;
|
||||
OnCharacterChanged?.Invoke();
|
||||
SaveCharacterSkinCloud();
|
||||
}
|
||||
|
||||
@@ -70,12 +70,12 @@ public class CharacterSelection : MonoBehaviour
|
||||
{
|
||||
LoadCharacterFromString(PlayerPrefs.GetString("skinData"));
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
FirebaseFirestore db = FirebaseFirestore.DefaultInstance;
|
||||
DocumentReference docRef = db.Collection("SkinData").Document(gplayAuth.userID);
|
||||
|
||||
docRef.GetSnapshotAsync().ContinueWithOnMainThread(task => {
|
||||
docRef.GetSnapshotAsync().ContinueWithOnMainThread(task => {
|
||||
DocumentSnapshot snapshot = task.Result;
|
||||
if(snapshot.Exists){
|
||||
|
||||
|
||||
@@ -79,7 +79,7 @@ public class PlayerAttack : NetworkBehaviour{
|
||||
Vector3 direction = GetPlayerLookDir();
|
||||
|
||||
//if(isServer){
|
||||
pnet.MagicalAttack(direction, magicalProjectileSpawnOffset, damage);
|
||||
pnet.MagicalAttack(direction, magicalProjectileSpawnOffset, damage);
|
||||
/*}else{
|
||||
Debug.Log(direction);
|
||||
CmdMagicalAttack(direction);
|
||||
@@ -91,10 +91,6 @@ public class PlayerAttack : NetworkBehaviour{
|
||||
magicalAttack(direction);
|
||||
}*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Vector3 GetPlayerLookDir(){
|
||||
Vector3 direction = Vector3.right;
|
||||
if(leftAnim.activeSelf){
|
||||
|
||||
@@ -2,6 +2,7 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Assets.HeroEditor4D.Common.Scripts.CharacterScripts;
|
||||
using Assets.HeroEditor4D.Common.Scripts.Common;
|
||||
using Assets.HeroEditor4D.Common.Scripts.Data;
|
||||
using Assets.HeroEditor4D.Common.Scripts.Enums;
|
||||
using Assets.HeroEditor4D.InventorySystem.Scripts.Elements;
|
||||
using UnityEngine;
|
||||
@@ -23,10 +24,25 @@ public class characterManager : MonoBehaviour
|
||||
void Update(){
|
||||
|
||||
if(Input.GetKeyDown(KeyCode.M)){
|
||||
ChangeWeapon();
|
||||
// ChangeWeapon();
|
||||
EquipBow();
|
||||
}
|
||||
}
|
||||
int weaponIndex = 52;
|
||||
public int bowIndex =0;
|
||||
public void EquipBow(){
|
||||
// bowIndex++;
|
||||
// if(bowIndex >= character.SpriteCollection.Bow.Count){
|
||||
// bowIndex=0;
|
||||
// }
|
||||
// Debug.Log("Equipping bow index " + bowIndex + " out of " + character.SpriteCollection.Bow.Count);
|
||||
|
||||
var item = character.SpriteCollection.Bow[16];
|
||||
EquipForAll(item, EquipmentPart.Bow);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void ChangeWeapon(){
|
||||
|
||||
// if(weaponIndex < character.SpriteCollection.MeleeWeapon1H.Count){
|
||||
@@ -38,11 +54,15 @@ public class characterManager : MonoBehaviour
|
||||
var item = character.SpriteCollection.MeleeWeapon1H[weaponIndex];
|
||||
// var sprite = character.SpriteCollection.MeleeWeapon1H.FindSprite("FireMageWand");
|
||||
|
||||
front.Equip(item,EquipmentPart.MeleeWeapon1H);
|
||||
back.Equip(item,EquipmentPart.MeleeWeapon1H);
|
||||
left.Equip(item,EquipmentPart.MeleeWeapon1H);
|
||||
right.Equip(item,EquipmentPart.MeleeWeapon1H);
|
||||
|
||||
EquipForAll(item,EquipmentPart.MeleeWeapon1H);
|
||||
}
|
||||
|
||||
void EquipForAll(ItemSprite item, EquipmentPart type){
|
||||
front.Equip(item, type);
|
||||
back.Equip(item, type);
|
||||
left.Equip(item, type);
|
||||
right.Equip(item, type);
|
||||
|
||||
}
|
||||
|
||||
public void SetActiveWeapon(int i){
|
||||
|
||||
@@ -14,7 +14,8 @@ using UnityEngine.SocialPlatforms;
|
||||
using Firebase.Auth;
|
||||
using UnityEngine.UI;
|
||||
using Newtonsoft.Json;
|
||||
using Unity.Properties;
|
||||
|
||||
|
||||
|
||||
public class playerNetwork : NetworkBehaviour
|
||||
{
|
||||
@@ -153,6 +154,7 @@ public class playerNetwork : NetworkBehaviour
|
||||
public List<string> completedQuests;
|
||||
|
||||
public GameObject projectile;
|
||||
public GameObject arrowRange;
|
||||
|
||||
public string selectedCharacterJson = CharacterSelection.selectedCharJson;
|
||||
|
||||
@@ -333,7 +335,6 @@ public class playerNetwork : NetworkBehaviour
|
||||
playerName = nameValue;
|
||||
}
|
||||
|
||||
|
||||
[Command(requiresAuthority =false)]
|
||||
void CmdRequestCharJson(){
|
||||
RpcBroadcastCharJson(myCharJson);
|
||||
@@ -359,6 +360,13 @@ public class playerNetwork : NetworkBehaviour
|
||||
character.AnimationManager.SetState((CharacterState)newVal);
|
||||
}
|
||||
|
||||
rangeEnemyFinder rangeEnemyFind;
|
||||
|
||||
enemyScript closestEnemy => rangeEnemyFind.targetEnemy;
|
||||
void Awake(){
|
||||
rangeEnemyFind = GetComponent<rangeEnemyFinder>();
|
||||
}
|
||||
|
||||
float attackTimer = 0;
|
||||
[HideInInspector]
|
||||
public PlayerAttack playerAttack;
|
||||
@@ -455,7 +463,6 @@ public class playerNetwork : NetworkBehaviour
|
||||
int prevLevel = GetLevelByXp(oldVal);
|
||||
int newLevle = GetLevelByXp(newVal);
|
||||
|
||||
|
||||
if(newLevle > prevLevel){
|
||||
int levelChange = newLevle - prevLevel;
|
||||
GameObject newObject = Instantiate(levelUpVfx , character.characterTransform());
|
||||
@@ -614,6 +621,73 @@ public class playerNetwork : NetworkBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
[SerializeField] public float arrowSpeed = 2.0f;
|
||||
[SerializeField] public float arrowShootOffset = 1;
|
||||
[SerializeField] public float arrowShootHeightOffset = 1;
|
||||
|
||||
public void OnRangeAttack(){
|
||||
if(attackTimer>0){
|
||||
return;
|
||||
}
|
||||
if(closestEnemy==null){return;}
|
||||
|
||||
attackTimer = ATTACK_COOLDOWN;
|
||||
|
||||
characterMan.EquipBow();
|
||||
PlayAttackAnim();
|
||||
|
||||
StartCoroutine(ArrowShootDelay());
|
||||
// arrowRange.transform.position = startingPosition;
|
||||
|
||||
//TODO: Deal Damage once it hits enemy
|
||||
|
||||
}
|
||||
public float arrowDelay;
|
||||
IEnumerator ArrowShootDelay (){
|
||||
|
||||
yield return new WaitForSeconds(arrowDelay);
|
||||
|
||||
Vector3 startingPosition = transform.position ;
|
||||
Vector3 destination = closestEnemy.transform.position;
|
||||
|
||||
//TODO: Move attack projectile from startingPosition to destination
|
||||
Vector3 direction = (destination - startingPosition).normalized;
|
||||
startingPosition += (direction * arrowShootOffset);
|
||||
startingPosition += (Vector3.up * arrowShootHeightOffset);
|
||||
destination += (Vector3.up * arrowShootHeightOffset);
|
||||
// Quaternion rotation = Quaternion.LookRotation(direction);
|
||||
float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;
|
||||
Quaternion rotation = Quaternion.Euler(0,0,angle - 90f);
|
||||
|
||||
GameObject newArrow = Instantiate(arrowRange , transform.position + (direction * arrowShootOffset) , rotation);
|
||||
|
||||
StartCoroutine(moveArrow(newArrow.transform , startingPosition , destination , closestEnemy));
|
||||
|
||||
}
|
||||
public int RangeDmg = 10;
|
||||
|
||||
IEnumerator moveArrow (Transform arrow , Vector3 start, Vector3 destination, enemyScript target ){
|
||||
|
||||
float dist = Vector3.Distance(start , destination);
|
||||
|
||||
float duration = dist/arrowSpeed;
|
||||
|
||||
float timer = 0f;
|
||||
|
||||
while(timer < duration){
|
||||
|
||||
arrow.position = Vector3.Lerp(start , destination , timer/duration);
|
||||
|
||||
timer += Time.deltaTime;
|
||||
yield return null;
|
||||
}
|
||||
|
||||
target.TakeDamage(RangeDmg, netId);
|
||||
|
||||
Destroy(arrow.gameObject);
|
||||
|
||||
}
|
||||
|
||||
public int MagicAttackWeaponIndex = 52;
|
||||
public void OnMagicAttack(){
|
||||
if(attackTimer > 0){
|
||||
@@ -621,7 +695,7 @@ public class playerNetwork : NetworkBehaviour
|
||||
}
|
||||
|
||||
attackTimer = ATTACK_COOLDOWN;
|
||||
characterMan.SetActiveWeapon(MagicAttackWeaponIndex);
|
||||
// characterMan.SetActiveWeapon(MagicAttackWeaponIndex);
|
||||
if(isLocalPlayer){
|
||||
PlayAttackAnim();
|
||||
//?
|
||||
@@ -730,10 +804,8 @@ public class playerNetwork : NetworkBehaviour
|
||||
GameManager.instance.SpawnPickup(type,transform.position + new Vector3(4,0));
|
||||
}
|
||||
|
||||
|
||||
int magicalDmg = 0;
|
||||
|
||||
|
||||
public void MagicalAttack(Vector3 direction, float magicalProjectileSpawnOffset, int dmg)
|
||||
{
|
||||
if (isServer)
|
||||
@@ -746,7 +818,6 @@ public class playerNetwork : NetworkBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Command]
|
||||
void CmdMagicalAttack(Vector3 direction, float magicalProjectileSpawnOffset, int dmg)
|
||||
{
|
||||
@@ -763,21 +834,19 @@ public class playerNetwork : NetworkBehaviour
|
||||
_projectile.shooterId = netId;
|
||||
|
||||
NetworkServer.Spawn(projectileSpawned);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void OnMagicalHit(enemyScript victim)
|
||||
{
|
||||
int damageamount = magicalDmg + (lvl * 5);
|
||||
|
||||
//magical damage with intelligance stat ?
|
||||
//int damageamount = magicalDmg + (lvl * 5);
|
||||
int damageamount = magicalDmg + (statManager.GetEffectiveValue("intelligence")*2);
|
||||
Debug.Log("magic damage amount " + damageamount);
|
||||
victim.TakeMagicalDamage(damageamount, netId);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public void GoBackMenu(){
|
||||
startClient.instance.networkManager.StopClient();
|
||||
SceneManager.LoadScene("GameLogin");
|
||||
|
||||
46
Assets/Script/rangeEnemyFinder.cs
Normal file
46
Assets/Script/rangeEnemyFinder.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class rangeEnemyFinder : MonoBehaviour
|
||||
{
|
||||
public float radius = 10;
|
||||
public enemyScript[] enemies;
|
||||
|
||||
public Transform lockIndicator;
|
||||
|
||||
private void OnDrawGizmos() {
|
||||
Gizmos.DrawWireSphere(transform.position, radius);
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
public enemyScript targetEnemy;
|
||||
|
||||
void Update()
|
||||
{
|
||||
enemies = FindObjectsOfType<enemyScript>();
|
||||
float closestDist = radius * 10f;
|
||||
targetEnemy = null;
|
||||
foreach(enemyScript enemy in enemies){
|
||||
float dist = Vector3.Distance((Vector2)enemy.transform.position,(Vector2)transform.position);
|
||||
if(dist < radius){
|
||||
if(dist < closestDist){
|
||||
targetEnemy = enemy;
|
||||
closestDist = dist;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lockIndicator.gameObject.SetActive(targetEnemy!= null);
|
||||
|
||||
if(targetEnemy != null){
|
||||
//show indicator
|
||||
lockIndicator.position = targetEnemy.transform.position + new Vector3 (0, 0.62f, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Script/rangeEnemyFinder.cs.meta
Normal file
11
Assets/Script/rangeEnemyFinder.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fdca2649edb8b4c0184a4d565a4fafa7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user