コード例 #1
0
 private void OnShot(PlayerShotInfo info)
 {
     if (_dead)
     {
         onBulletDeath(info);
     }
 }
コード例 #2
0
ファイル: ShotController.cs プロジェクト: ly774508966/VRG
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
//			print ("mouse down");
//			print ("pointer down");
            RaycastHit hit;
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            if (Physics.Raycast(ray, out hit))
            {
                Transform objectHit = hit.transform;

                print("Tapped: " + objectHit.gameObject.name + " @" + Time.time);

                PlayerShotInfo playerShotInfo = new PlayerShotInfo(playerOneCharacter);
                playerShotInfo.shotLocation = hit.collider.gameObject;
                playerShotInfo.target       = Utility.GetParentCharacterRecursively(playerShotInfo.shotLocation.transform);
//				playerShotInfo.target = playerShotInfo.shotLocation.transform.parent.parent.GetComponent<ScriptCharacterSheet>();

                playerShotInfo.shotRay      = ray;
                playerShotInfo.shotLocation = hit.transform.gameObject;
                ScriptGameMaster.Instance.ExecuteAction(playerShotInfo);
            }
        }
    }
コード例 #3
0
 public void Shoot(PlayerShotInfo info)
 {
     if (!canShoot)
     {
         return;
     }
     onDamage(info.damage);
     onShot(info);
 }
コード例 #4
0
ファイル: ScriptGameMaster.cs プロジェクト: ly774508966/VRG
    Result GetActionResult(PlayerShotInfo playerShotInfo)
    {
        CharacterSheet actingCharacter = playerShotInfo.shooter;
        Result         result          = new Result(actingCharacter);

        result.playerShotInfo = playerShotInfo;

        //Debug.Log ("Action result init: " + playerShotInfo.shotRay.ToString ());
//		print ("player shot info target" + playerShotInfo.target.name);
        if (playerShotInfo.target)
        {
            result.targetCharacter = playerShotInfo.target;
            result.hitLocation     = playerShotInfo.shotLocation;
            //Debug.Log (hitLocation.name);

            //Get attack stats
            result.actingAttack  = actingCharacter.readyAttack;
            result.targetDefense = result.targetCharacter.readyDefense;

            //Calculate success number
            result.hitPercentage = GetHitPercentage(result.actingAttack, result.targetDefense);
            result.successNumber = 100 - result.hitPercentage;

            //Roll d100
            result.roll = GetRandom1ToN(100);

            //If roll is greater than the success number, attack succeeds
            result.rollExcess = result.roll - result.successNumber;
//			print ("acting attack, target defense" + );
            if (result.rollExcess >= 1)
            {
                result.success = true;

                //Set damage properties
                result.grossDamage           = actingCharacter.readyDamage;
                result.damageType            = actingCharacter.activeItem.damageType;
                result.targetGrossHitProfile = GetGrossHitProfile(result);

                //Apply armor (pending)
                result.targetNetHitProfile = SumHitProfiles(result.targetGrossHitProfile, result.targetCharacter.resistanceHitProfile);
            }
            else
            {
                result.success = false;
            }
        }
        else
        {
            result.success = false;
        }
        return(result);
    }
コード例 #5
0
    private void OnBulletDeath(PlayerShotInfo info)
    {
        SetRagdoll(true);
        Vector3 baseForce = info.direction * (deathForceScale * info.damage);

        foreach (Rigidbody rb in _rbs)
        {
            Vector3 closestPoint = rb.GetComponent <Collider>().ClosestPoint(info.hit.point);
            float   invSquare    = Vector3.SqrMagnitude((closestPoint - info.hit.point) * invSquareDistanceScale) + .02f;
            // rb.AddForceAtPosition(baseForce / invSquare, closestPoint);
            rb.AddForceAtPosition(baseForce / invSquare, info.hit.point);
        }
    }
コード例 #6
0
ファイル: ScriptGameMaster.cs プロジェクト: ly774508966/VRG
//ACTION RESOLUTION

    //Resolve character's action- default overload
//	void ExecuteAction (ScriptCharacterSheet hotSheet)
//	{
//		//Deprecated?
//
//		//New result
//		Result result = null;
//
//		if (hotSheet.target) {
//			ScriptCharacterSheet targetSheet = hotSheet.target;
//
//			//Get result of attempted action
//			result = GetActionResult (hotSheet, targetSheet);
//
//			//Change states
//			if (result.success) {
//				//Reduce health
//				SumHitProfiles (result.targetCharacter.currentHitProfile, result.targetNetHitProfile);
//			}
//
//			//Apply damage results
//			if (targetSheet.currentHitProfile.head <= 0 || targetSheet.currentHitProfile.body <= 0) {
//				KillCharacter (targetSheet);
//
//				//Start encounter cam on dead character
//				RunCinematicCamera (result.targetCharacter.GetComponent<ScriptCharacterController> ());
//			}
//
//			//Initiate visual and audio effects
//			scriptPhysicsController.SendMessage ("InitiateActionEffect", result);
//
//		} else {
//			Debug.Log (result.actingCharacter.ToString () + " attacks nothing.");
//		}
//
//		//Reset Wait Time to delay
//		hotSheet.waitTime = hotSheet.activeItem.itemStatProfile.cooldownAspect;
//
//		//Log action to console
//		string hotLine = string.Format ("{0} attacks {1} ({2:00} ATT vs {3:00} DEF: {4:00}%). Roll: {5}",
//		                                new object[] {
//			result.actingCharacter.fullName,
//			result.targetCharacter.fullName,
//			result.actingAttack,
//			result.targetDefense,
//			result.hitPercentage,
//			result.roll
//		});
//		if (result.success) {
//			hotLine += string.Format (" > {0}. {1} shoots {2} for {3} {4} damage.",
//			                          new object[]{result.successNumber, result.actingCharacter.fullName,
//				result.targetCharacter.fullName, result.grossDamage, result.damageType});
//		} else {
//			hotLine += string.Format (" <= {0}. {1} misses.", result.successNumber, result.actingCharacter.fullName);
//		}
//		ConsoleAddLine (hotLine);
//
//		//Display damage
//		GameObject currentDamageDisplay = Instantiate (
//			damageDisplay, new Vector3 (result.targetCharacter.gameObject.transform.position.x,
//		                           result.targetCharacter.gameObject.transform.position.y, damageDisplayDepth), Quaternion.identity) as GameObject;
//		currentDamageDisplay.GetComponent<ScriptDisplayContainer> ().camera00 = overviewCamera;
//		TextMesh statusChangeText = currentDamageDisplay.GetComponentInChildren<TextMesh> ();
//		if (result.success) {
//			statusChangeText.text = "-" + result.grossDamage + "HP";
//		} else {
//			statusChangeText.text = "Miss";
//		}
//	}

    //Resolve player input shot- 2nd overload
    public void ExecuteAction(PlayerShotInfo playerShotInfo)
    {
        //Debug.Log("Execute action ray " + playerShotInfo.shotRay.ToString());

        //New result
        Result         result      = null;
        CharacterSheet hotSheet    = playerShotInfo.shooter;
        CharacterSheet targetSheet = playerShotInfo.target;

        //Add playershotinfo to result and resolve action
        result = GetActionResult(playerShotInfo);
//		print ("player shot info target: " + playerShotInfo.target.fullName);
        if (playerShotInfo.target)
        {
            print("Found target from PSI");
            //Change states
            if (result.success)
            {
                //Reduce health
                print("result target hit profile: " + result.targetNetHitProfile.head + ", " + result.targetNetHitProfile.body + ", " + result.targetNetHitProfile.leftArm);
                SumHitProfiles(result.targetCharacter.currentHitProfile, result.targetNetHitProfile);

                //Apply damage results
                print("Applying damage results: " + targetSheet.currentHitProfile.head + ", " + targetSheet.currentHitProfile.body);
                if (targetSheet.currentHitProfile.head <= 0 || targetSheet.currentHitProfile.body <= 0)
                {
                    //Debug.Log (targetSheet.fullName + "Should be dead");
                    KillCharacter(targetSheet);

                    //Start encounter cam on dead character
                    RunCinematicCamera(result.targetCharacter.GetComponent <ScriptCharacterController> ());
                }
            }

            //Set selector cooldown?
            //hotSheet.waitTime = hotSheet.activeItem.itemStatProfile.cooldownAspect;

            //Log action to console
            string hotLine = string.Format("{0} attacks {1} ({2:00} ATT vs {3:00} DEF: {4:00}%). Roll: {5}",
                                           new object[] {
                result.actingCharacter.fullName,
                result.targetCharacter.fullName,
                result.actingAttack,
                result.targetDefense,
                result.hitPercentage,
                result.roll
            });
            if (result.success)
            {
                hotLine += string.Format(" > {0}. {1} shoots {2} for {3} {4} damage.",
                                         new object[] { result.successNumber, result.actingCharacter.fullName,
                                                        result.targetCharacter.fullName, result.grossDamage, result.damageType });
            }
            else
            {
                hotLine += string.Format(" <= {0}. {1} misses.", result.successNumber, result.actingCharacter.fullName);
            }
            ConsoleAddLine(hotLine);

            //Display damage
            GameObject currentDamageDisplay = Instantiate(
                damageDisplay, new Vector3(result.targetCharacter.gameObject.transform.position.x,
                                           result.targetCharacter.gameObject.transform.position.y, damageDisplayDepth), Quaternion.identity) as GameObject;
            currentDamageDisplay.GetComponent <ScriptDisplayContainer> ().camera00 = overviewCamera;
            TextMesh statusChangeText = currentDamageDisplay.GetComponentInChildren <TextMesh> ();
            if (result.success)
            {
                statusChangeText.text = "-" + result.grossDamage + "HP";
            }
            else
            {
                statusChangeText.text = "Miss";
            }
        }
        //Initiate visual and audio effects
        PhysicsController.Instance.InitiateActionEffect(result);
    }
コード例 #7
0
    // Update is called once per frame
    void Update()
    {
        //if(oscillationIsEnabled)
        //{

        if (shotFired)
        {
            cooldownTimer += Time.deltaTime;
            if (cooldownTimer >= cooldown)
            {
                shotFired      = false;
                shotInputReady = true;
                lineRenderer.SetColors(Color.green, Color.green);
            }
        }

        if (scriptCharacterSheet.activeItem != null)
        {
            //Set currentAngle
            if (!oscillationIsPaused)
            {
                if (oscillationMode == OscillationMode.Ascending)
                {
                    if (currentAngle <= finishAngle)
                    {
                        currentAngle += speedConstant;
                    }
                    else
                    {
                        oscillationMode = OscillationMode.Descending;
                        currentAngle   -= speedConstant;
                    }
                }
                else if (oscillationMode == OscillationMode.Descending)
                {
                    if (currentAngle >= startAngle)
                    {
                        currentAngle -= speedConstant;
                    }
                    else
                    {
                        oscillationMode = OscillationMode.Ascending;
                        currentAngle   += speedConstant;
                    }
                }
                else
                {
                    Debug.Log("Invalid oscillation mode");
                }
            }
            else
            {
                //Oscillation paused, do not change angle
            }


            //Update ray
            currentRay = GetSelectionRay(currentAngle);
            //Debug.DrawRay(hotRay.origin, hotRay.direction
            //            * scriptCharacterSheet.activeItem.itemStatProfile.maxRangeAspect
            //         , Color.green);

            //Draw line
            lineRenderer.SetPosition(0, currentRay.origin);
            lineRenderer.SetPosition(1, currentRay.direction * scriptCharacterSheet.activeItem.itemStatProfile.maxRangeAspect + currentRay.origin);
            //Debug.Log (hotRay.origin.ToString () + "<>" + hotRay.direction.ToString());
        }

        //Input
        if (Input.GetKeyDown(playerKeyCode))
        {
            if (shotInputReady)
            {
                shotLoaded = true;
            }
        }

        if (Input.GetKey(playerKeyCode) && shotLoaded)
        {
            //shotInputReady = false;
            oscillationIsPaused = true;
        }
        else
        {
            oscillationIsPaused = false;
        }

        if (Input.GetKeyUp(playerKeyCode) && shotLoaded)
        {
            Debug.Log("Button release ray: " + currentRay.ToString());

            //Fire shot
            RaycastHit hit;
            if (Physics.Raycast(currentRay, out hit, scriptCharacterSheet.activeItem.itemStatProfile.maxRangeAspect, layerMask))
            {
                PlayerShotInfo playerShotInfo = new PlayerShotInfo(scriptCharacterSheet);
                playerShotInfo.shotLocation = hit.collider.gameObject;
                playerShotInfo.target       = playerShotInfo.shotLocation.transform.parent.parent.GetComponent <CharacterSheet>();

                playerShotInfo.shotRay = currentRay;
                scriptGameMaster.SendMessage("ExecuteAction", playerShotInfo);
            }
            else
            {
                PlayerShotInfo playerShotInfo = new PlayerShotInfo(scriptCharacterSheet);
                playerShotInfo.shotLocation = null;
                playerShotInfo.shotRay      = currentRay;
                Debug.Log("shotray Assigned: " + playerShotInfo.shotRay.ToString());
                scriptGameMaster.SendMessage("ExecuteAction", playerShotInfo);
                //Debug.Log ("Miss ");
            }

            //Set as not ready
            shotInputReady = false;
            shotLoaded     = false;
            shotFired      = true;
            lineRenderer.SetColors(Color.red, Color.red);
            cooldownTimer = 0;
        }
        //}
    }