예제 #1
0
Profession Profession::byName(std::string name) {
  if(name == "Student") {
    return Profession("Student", Attributes(10, 10, 10), Stats(0, 0, 1500));
  }
  
  throw std::string("Not such profession exists");
}
예제 #2
0
long Player::ParseTalkTokens(char *write_buffer, char *input_buffer)
{
    char *profession[] =
    {
        "Warrior",
        "Trader",
        "Explorer"
    };
    char *race[] =
    {
        "Terran",
        "Jenquai",
        "Progen"
    };
	char *aprofession[] =
	{
		"a Warrior",
		"a Trader",
		"an Explorer"
	};

	char *ptr = write_buffer;
	char *token_ptr;

	long length = 0;
	//scan text for flags
	token_ptr = strchr(input_buffer, '@');

	if (token_ptr)
	{
		char *tree_ptr = input_buffer;
		while (*tree_ptr != 0)
		{
			if (*tree_ptr == '@')
			{
				token_ptr = tree_ptr+1;
				switch (token_ptr[0])
				{
				case 'a': //a[n] @profession
					if (strncmp(token_ptr, "aprofession", 11) == 0)
					{
						strcpy(ptr, aprofession[Profession()]);
						ptr += strlen(aprofession[Profession()]);
						tree_ptr += 11;
					}
					break;
				case 'c': //class (== profession)
					if (token_ptr[1] == 'l' && token_ptr[2] == 'a' && token_ptr[3] == 's' &&
						token_ptr[1] == 's')
					{
						strcpy(ptr, profession[Profession()]);
						ptr += strlen(profession[Profession()]);
						tree_ptr += 10;
					}
					break;
				case 'n': //name
					if (token_ptr[1] == 'a' && token_ptr[2] == 'm' && token_ptr[3] == 'e')
					{
						strcpy(ptr, Name());
						ptr += strlen(Name());
						tree_ptr += 4;
					}
					break;
				case 'r': //race
					if (token_ptr[1] == 'a' && token_ptr[2] == 'c' && token_ptr[3] == 'e')
					{
						strcpy(ptr, race[Race()]);
						ptr += strlen(race[Race()]);
						tree_ptr += 4;
					}
					break;
				case 'p':
					if (strncmp(token_ptr, "profession", 10) == 0)
					{
						strcpy(ptr, profession[Profession()]);
						ptr += strlen(profession[Profession()]);
						tree_ptr += 10;
					}
					break;
				default:
					*ptr++ = *tree_ptr;
					break;
				}
			}
			else
			{
				*ptr++ = *tree_ptr;
			}
			tree_ptr++;
		}
	}
	else
	{
		strcpy(ptr, input_buffer);
		ptr += strlen(input_buffer);
	}

	length = (long) (ptr - write_buffer);

	return length;
}
void Player::ShipDamage(long source_id, float weapon_damage, short type)
{
	bool Ignored = false, OnDamage = false;

	if (!m_ObjectMgr)
	{
		return;
	}

    Object *obj = m_ObjectMgr->GetObjectFromID(source_id);
    if (obj && !DebugPlayer())
    {
		float TakeDamage = 0;
		float DamageAbsorbed = 0;

        //terminate warp, prospecting
        //TerminateWarp();						// This should only be done for hull damage
        AbortProspecting(true, false);

		if (m_DamageAbsorb > 0)
		{
			TakeDamage = m_DamageAbsorb - weapon_damage;
			if (TakeDamage < 0)
			{
				// Take damage when we run out of absorb
				m_DamageAbsorb = 0;
				TakeDamage *= -1;
				// Calculate the damage absorbed by the shield
				DamageAbsorbed -= (weapon_damage - TakeDamage);
			}
			else
			{
				// We take no damage because of the shield
				TakeDamage = 0;
				m_DamageAbsorb -= weapon_damage;
				// Calculate the damage absorbed by the shield
				DamageAbsorbed -= weapon_damage;
			}
		}
		else
		{
			// No shield take all damage
			TakeDamage = weapon_damage;
		}

		// TODO: Add code to reduce damage from buffs and deflects

		/*****************
		* Damage reduction section.
		******************/
		float redux_percent;
		float BeforeDamage = TakeDamage;
		switch(type)
		{
		case DAMAGE_IMPACT:
			//is this needed?
			redux_percent = m_Stats.GetStat(STAT_IMPACT_DEFLECT);
			TakeDamage *= (1.0f - (redux_percent > 0.5f ? 0.5f : redux_percent));
			break;
		case DAMAGE_EXPLOSIVE:
			redux_percent = m_Stats.GetStat(STAT_EXPLOSIVE_DEFLECT);
			TakeDamage *= (1.0f - (redux_percent > 0.5f ? 0.5f : redux_percent));
			break;
		case DAMAGE_PLASMA:
			redux_percent = m_Stats.GetStat(STAT_PLASMA_DEFLECT);
			TakeDamage *= (1.0f - (redux_percent > 0.5f ? 0.5f : redux_percent));
			break;
		case DAMAGE_ENERGY:
			redux_percent = m_Stats.GetStat(STAT_ENERGY_DEFLECT);
			TakeDamage *= (1.0f - (redux_percent > 0.5f ? 0.5f : redux_percent));
			break;
		case DAMAGE_EMP:
			redux_percent = m_Stats.GetStat(STAT_EMP_DEFLECT);
			TakeDamage *= (1.0f - (redux_percent > 0.5f ? 0.5f : redux_percent));
			break;
		case DAMAGE_CHEMICAL:
			redux_percent = m_Stats.GetStat(STAT_CHEM_DEFLECT);
			TakeDamage *= (1.0f - (redux_percent > 0.5f ? 0.5f : redux_percent));
			break;
		}

		// Find out if we absorbed any damage with the deflects
		DamageAbsorbed -= (BeforeDamage - TakeDamage);

        SendClientDamage(GameID(), source_id, TakeDamage, DamageAbsorbed, type, 1);

        bool send_shield_hit = GetShieldValue() >= TakeDamage ? true : false;
        if (send_shield_hit)
        {
            m_Mutex.Lock();

			Player *p = (0);
			
			while (g_PlayerMgr->GetNextPlayerOnList(p, m_RangeList))
			{
                p->SendObjectToObjectLinkedEffect(this, obj, 0x0021, 0x0003);
            }

            m_Mutex.Unlock();
        }

        //DB: Note - Shake does not occur on first hit
        //Shake stops when you run out of shields as it expects hull to decrease then
        ShipIndex()->Shake.SetDamage(TakeDamage);

        float shield_level = GetShieldValue();
		float dmg_reduce_percent = 0;

		if(m_CurrentSkill && m_CurrentSkill->SkillInterruptable(&Ignored, &OnDamage, &Ignored))
		{
			if(OnDamage)
			{
				m_CurrentSkill->InterruptSkillOnDamage(TakeDamage);
			}
		}

        if (TakeDamage > shield_level)
        {
            float hull_dmg = TakeDamage - shield_level;
            if (shield_level > 0.0f)
            {
                RemoveShield(shield_level);
            }

			//if dmg type is chemical, do bonus dmg to hull
			if(type == DAMAGE_CHEMICAL)
			{
				hull_dmg *= 1.2f; //20% bonus damage
			}

			//calculate in damage control, TW/PW only
			//Note: This is normal %, if you want the "effective percent" (like Turbo uses) you need to change this.
			if ( (Profession() == PROFESSION_WARRIOR && Race() == RACE_PROGEN) || 
				(Profession() == PROFESSION_WARRIOR && Race() == RACE_TERRAN) )
			{
				dmg_reduce_percent = 1.0f - m_Stats.GetStat(STAT_DAMAGE_CONTROL);
				if(dmg_reduce_percent < 0)
				{
					dmg_reduce_percent = 0;
				}
				hull_dmg = hull_dmg * dmg_reduce_percent;
			}

			//if dmg type is EMP, take no damage to hull (EMP can't hurt the hull)
			if(type == DAMAGE_EMP)
			{
				hull_dmg = 0;
			}

            RemoveHull(hull_dmg, obj);
			TerminateWarp();
        }
        else
        {
			//bonus damage for plasma
			if(type == DAMAGE_PLASMA)
			{
				TakeDamage *= 1.2f; //20% bonus damage
			}
            RemoveShield(TakeDamage);
        }
    }
}