<commit_before>﻿#include "stdafx.h"
#include "Missile.h"
#include "Scheduler.h"
#include "ClientManager.h"
#include "ClientSession.h"
#include "GameManager.h"
#include "MissileManager.h"
#include "Player.h"


Missile::Missile()
{
	m_UnitType = UNIT_MISSILE;
	m_MissileType = MS_NONE;
	m_InUse = false;
	m_Range = 0.0f;
	m_Livetime = 0.0f;
}

Missile::~Missile()
{
}


void Missile::SetMissileInit(int playerId, b2Vec2 initPos, float scale)
{
	m_PlayerID = playerId;
	b2BodyDef bodyDef;
	bodyDef.type = b2_dynamicBody;
	bodyDef.position.Set(initPos.x, initPos.y);
	m_Body = GGameManager->GetWolrd()->CreateBody(&bodyDef);

	b2CircleShape circle;
	circle.m_radius = scale / PTM_RATIO;

	b2FixtureDef fixtureDef;
	fixtureDef.shape = &circle;
	fixtureDef.density = 1.0f;
	fixtureDef.friction = 0.3f;
	fixtureDef.restitution = 0.7f;

	m_Body->CreateFixture(&fixtureDef);
	m_Body->SetUserData(this);
}

void Missile::MissileShoot()
{
	auto currentPos = m_Body->GetPosition();
	auto direction = m_TargetPos - currentPos;
	auto distance = sqrt(pow(direction.x, 2) + pow(direction.y, 2));

	b2Vec2 rangePos;
	rangePos.x = direction.x*m_Range / distance;
	rangePos.y = direction.y*m_Range / distance;
	m_TargetPos = rangePos;

	direction = rangePos - currentPos;
	distance = sqrt(pow(direction.x, 2) + pow(direction.y, 2));
	direction *= m_Speed / distance;
	m_Body->SetLinearVelocity(direction);

	GClientManager->GetClient(m_PlayerID)->MissileBroadCast(m_PlayerID, m_UnitID, currentPos, m_TargetPos);
	m_State->TryMove(this);
}

void Missile::ConsumeLiveTime(float costTime)
{

}

void Missile::Extinction()
{
	Crashing(false);

	auto player = GGameManager->SearchPlayer(m_PlayerID);
	player->UnitListPop(m_UnitID);

	if (m_InUse)
	{<commit_msg>[S] MissileShooting 공식 수정<commit_after>﻿#include "stdafx.h"
#include "Missile.h"
#include "Scheduler.h"
#include "ClientManager.h"
#include "ClientSession.h"
#include "GameManager.h"
#include "MissileManager.h"
#include "Player.h"


Missile::Missile()
{
	m_UnitType = UNIT_MISSILE;
	m_MissileType = MS_NONE;
	m_InUse = false;
	m_Range = 0.0f;
	m_Livetime = 0.0f;
}

Missile::~Missile()
{
}


void Missile::SetMissileInit(int playerId, b2Vec2 initPos, float scale)
{
	m_PlayerID = playerId;
	b2BodyDef bodyDef;
	bodyDef.type = b2_dynamicBody;
	bodyDef.position.Set(initPos.x, initPos.y);
	m_Body = GGameManager->GetWolrd()->CreateBody(&bodyDef);

	b2CircleShape circle;
	circle.m_radius = scale / PTM_RATIO;

	b2FixtureDef fixtureDef;
	fixtureDef.shape = &circle;
	fixtureDef.density = 1.0f;
	fixtureDef.friction = 0.3f;
	fixtureDef.restitution = 0.7f;

	m_Body->CreateFixture(&fixtureDef);
	m_Body->SetUserData(this);
}

void Missile::MissileShoot()
{
	auto currentPos = m_Body->GetPosition();
	auto direction = m_TargetPos - currentPos;
	auto distance = sqrt(pow(direction.x, 2) + pow(direction.y, 2));

	b2Vec2 rangePos;
	rangePos.x = direction.x*m_Range / distance + currentPos.x;
	rangePos.y = direction.y*m_Range / distance + currentPos.y;
	m_TargetPos = rangePos;

	auto newDirection = rangePos - currentPos;
	newDirection *= m_Speed / m_Range;

	m_Body->SetLinearVelocity(newDirection);

	GClientManager->GetClient(m_PlayerID)->MissileBroadCast(m_PlayerID, m_UnitID, currentPos, m_TargetPos);
	m_State->TryMove(this);
}

void Missile::ConsumeLiveTime(float costTime)
{

}

void Missile::Extinction()
{
	Crashing(false);

	auto player = GGameManager->SearchPlayer(m_PlayerID);
	player->UnitListPop(m_UnitID);

	if (m_InUse)
	{
{'fraction_non_alphanumeric': 0.13635053329489766, 'fraction_numerical': 0.012107235514557509, 'mean_word_length': 5.647509578544061, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2118713', 'n_tokens_mistral': 1409, 'n_tokens_neox': 1371, 'n_words': 233}