void VScrollBarOverlayWindow::ShouldHide()
{
  if (IsVisible())
  {
    if (!(HasState(ThumbState::MOUSE_DOWN)) &&
        !(HasState(ThumbState::MOUSE_NEAR)) &&
        !(HasState(ThumbState::MOUSE_INSIDE)))
    {
      animation::StartOrReverse(show_animator_, animation::Direction::BACKWARD);
    }
  }
}
void VScrollBarOverlayWindow::ShouldShow()
{
  if (!IsVisible())
  {
    if (HasState(ThumbState::MOUSE_DOWN) ||
        HasState(ThumbState::MOUSE_NEAR))
    {
      ShowWindow(true);
      PushToFront();
      animation::StartOrReverse(show_animator_, animation::Direction::FORWARD);
    }
  }
}
Beispiel #3
0
bool Game_Battler::UseSkill(int skill_id) {
	const RPG::Skill* skill = ReaderUtil::GetElement(Data::skills, skill_id);
	if (!skill) {
		Output::Warning("UseSkill: Can't use skill with invalid ID %d", skill_id);
		return false;
	}

	bool was_used = false;

	if (skill->type == RPG::Skill::Type_normal || skill->type >= RPG::Skill::Type_subskill) {
		// Only takes care of healing skills outside of battle,
		// the other skill logic is in Game_BattleAlgorithm

		if (!(skill->scope == RPG::Skill::Scope_ally ||
			  skill->scope == RPG::Skill::Scope_party ||
			  skill->scope == RPG::Skill::Scope_self)) {
			return false;
		}

		// Skills only increase hp and sp outside of battle
		if (skill->power > 0 && skill->affect_hp && !HasFullHp()) {
			was_used = true;
			ChangeHp(skill->power);
		}

		if (skill->power > 0 && skill->affect_sp && !HasFullSp()) {
			was_used = true;
			ChangeSp(skill->power);
		}

		for (int i = 0; i < (int) skill->state_effects.size(); i++) {
			if (skill->state_effects[i]) {
				if (skill->state_effect) {
					was_used |= !HasState(Data::states[i].ID);
					AddState(Data::states[i].ID);
				} else {
					was_used |= HasState(Data::states[i].ID);
					RemoveState(Data::states[i].ID);
				}
			}
		}
	} else if (skill->type == RPG::Skill::Type_teleport || skill->type == RPG::Skill::Type_escape) {
		was_used = true;
	} else if (skill->type == RPG::Skill::Type_switch) {
		Game_Switches[skill->switch_id] = true;
		was_used = true;
	}

	return was_used;
}
Beispiel #4
0
bool Game_Battler::UseSkill(int skill_id) {
	const RPG::Skill& skill = Data::skills[skill_id - 1];

	bool was_used = false;

	switch (skill.type) {
		case RPG::Skill::Type_normal:
		case RPG::Skill::Type_subskill:
			// Only takes care of healing skills outside of battle,
			// the other skill logic is in Game_BattleAlgorithm

			if (!(skill.scope == RPG::Skill::Scope_ally ||
				skill.scope == RPG::Skill::Scope_party ||
				skill.scope == RPG::Skill::Scope_self)) {
				return false;
			}

			// Skills only increase hp and sp outside of battle
			if (skill.power > 0 && skill.affect_hp && !HasFullHp()) {
				was_used = true;
				ChangeHp(skill.power);
			}

			if (skill.power > 0 && skill.affect_sp && !HasFullSp()) {
				was_used = true;
				ChangeSp(skill.power);
			}

			for (int i = 0; i < (int)skill.state_effects.size(); i++) {
				if (skill.state_effects[i]) {
					if (skill.state_effect) {
						was_used |= !HasState(Data::states[i].ID);
						AddState(Data::states[i].ID);
					} else {
						was_used |= HasState(Data::states[i].ID);
						RemoveState(Data::states[i].ID);
					}
				}
			}
		case RPG::Skill::Type_teleport:
		case RPG::Skill::Type_escape:
			// ToDo: Show Teleport/Escape target menu
			break;
		case RPG::Skill::Type_switch:
			Game_Switches[skill.switch_id] = true;
			return true;
	}

	return was_used;
}
bool Database::WaitForDefinedState(TuningState newstate) {
   if (HasState(newstate))
      return true;
      
   DatabaseLock lock(this);
   //wait at most 8 seconds (in general, PAT should be acquired in less than 1 second)
   for (int i=0; i<8; i++) {
      if (HasState(newstate)) {
         return true;
      }
      stateVar.TimedWait(mutex, 1000);
   }
   return false;
}
void Game_Battler::AddState(int state_id) {
	std::vector<int16_t>& states = GetStates();
	if (state_id > 0 && !HasState(state_id)) {
		states.push_back(state_id);
		std::sort(states.begin(), states.end());
	}
}
Beispiel #7
0
void InputSystem::AddStateHandler(uint32_t state, InputStateHandler handler)
{
	if (HasState(state))
	{
		mStateHandlers[state] = handler;
	}
}
Beispiel #8
0
ActionState* 
ActionState::GetState( int id )
{
	if ( id == m_id )
	{
		return this;
	}

	if ( !HasState( id ) )
	{
		return (ActionState*)0;
	}

	StateList::iterator i( m_childs.begin() );
	StateList::iterator iEnd( m_childs.end() );

	for ( ; i != iEnd; ++i )
	{
		ActionState* child = *i;
		K_ASSERT( child != 0 );

		if ( child->HasState( id ) )
		{
			return child->GetState( id );
		}
	}

	return (ActionState*)0;
}
void FvAura::_OnTimeTick(FvTimeEventNodeInterface&)
{
	//! 计算定时次数
	if(HasState(FvAuraState::ACTIVE))
	{
		_OnTick();
	}
}
void VScrollBarOverlayWindow::ThumbInsideSlider()
{
  if (!HasState(ThumbState::INSIDE_SLIDER))
  {
    AddState(ThumbState::INSIDE_SLIDER);
    UpdateTexture();
  }
}
void VScrollBarOverlayWindow::ThumbOutsideSlider()
{
  if (HasState(ThumbState::INSIDE_SLIDER))
  {
    RemoveState(ThumbState::INSIDE_SLIDER);
    UpdateTexture();
  }
}
bool Database::retrievePat(SI::PAT &Pat) {
   if (HasState(TuningStatePat)) {
      DatabaseLock lock(this);
      Pat=pat;
      return true;
   }
   return false;
}
bool FSocketBSDIPv6::HasPendingConnection(bool& bHasPendingConnection)
{
	bool bHasSucceeded = false;
	bHasPendingConnection = false;

	// make sure socket has no error state
	if (HasState(EIPv6SocketInternalState::HasError) == EIPv6SocketInternalState::No)
	{
		// get the read state
		EIPv6SocketInternalState::Return State = HasState(EIPv6SocketInternalState::CanRead);
		
		// turn the result into the outputs
		bHasSucceeded = State != EIPv6SocketInternalState::EncounteredError;
		bHasPendingConnection = State == EIPv6SocketInternalState::Yes;
	}

	return bHasSucceeded;
}
Beispiel #14
0
//+----------------------------------------------------------------------------------------------------
void FvAura::Active(const bool bUpdate)
{
	if(HasState(FvAuraState::ACTIVE))
	{
		return;
	}
	_AddState(FvAuraState::ACTIVE);
	_OnActive(bUpdate);
}
Beispiel #15
0
void FvAura::Deactive(const bool bUpdate)
{
	if(!HasState(FvAuraState::ACTIVE))
	{
		return;
	}
	_DelState(FvAuraState::ACTIVE);
	_OnDeactive(bUpdate);
}
Beispiel #16
0
void FvAura::End()
{
	if(HasState(FvAuraState::END))
	{
		return;
	}
	_AddState(FvAuraState::END);
	_OnEnd();
	_Destroy();
}
bool FSocketBSDIPv6::Wait(ESocketWaitConditions::Type Condition, FTimespan WaitTime)
{
	if ((Condition == ESocketWaitConditions::WaitForRead) || (Condition == ESocketWaitConditions::WaitForReadOrWrite))
	{
		if (HasState(EIPv6SocketInternalState::CanRead, WaitTime) == EIPv6SocketInternalState::Yes)
		{
			return true;
		}
	}

	if ((Condition == ESocketWaitConditions::WaitForWrite) || (Condition == ESocketWaitConditions::WaitForReadOrWrite))
	{
		if (HasState(EIPv6SocketInternalState::CanWrite, WaitTime) == EIPv6SocketInternalState::Yes)
		{
			return true;
		}
	}

	return false;
}
Beispiel #18
0
void 
ActionState::attach( ActionState* state )
{
	K_ASSERT( state != 0 );

	if ( HasState( state->GetId() ) )
	{
		return;
	}

	m_childs.push_back( state );
}
Beispiel #19
0
////////////////////////////////////////////////////////////////////////////////
/// Gets the value of a device state from the adapter.
///
/// @ErrorHandling Throws a std::runtime_error if CDevice::HasState returns
/// false for the passed string identifier.
/// @pre The device must recognize the passed signal.
/// @post m_adapter is queried for the value of the passed signal.
/// @param signal The string identifier for the state signal to retrieve.
/// @return The current value of the specified state signal.
///
/// @limitations This function can still fail even if CDevice::HasState returns
/// true. This case happens when m_adapter is not configured to store all the
/// data required for this device.
////////////////////////////////////////////////////////////////////////////////
SignalValue CDevice::GetState(std::string signal) const
{
    Logger.Trace << __PRETTY_FUNCTION__ << std::endl;

    if( !HasState(signal) )
    {
        Logger.Error << "Bad Device State: " << signal << "\n" << m_devid
                << "\n" << m_devinfo << std::endl;
        throw std::runtime_error("Bad Device State: " + signal);
    }

    return m_adapter->GetState(m_devid, signal);
}
void VScrollBarOverlayWindow::SetThumbOffsetY(int y)
{
  int const new_offset = GetValidOffsetYValue(y);

  if (new_offset != mouse_offset_y_)
  {
    if (HasState(ThumbState::MOUSE_DOWN))
      MouseDragging();

    mouse_offset_y_ = new_offset;
    QueueDraw();
  }
}
ESocketConnectionState FSocketBSDIPv6::GetConnectionState(void)
{
	ESocketConnectionState CurrentState = SCS_ConnectionError;

	// look for an existing error
	if (HasState(EIPv6SocketInternalState::HasError) == EIPv6SocketInternalState::No)
	{
		// get the write state
		EIPv6SocketInternalState::Return State = HasState(EIPv6SocketInternalState::CanWrite);
		
		// translate yes or no (error is already set)
		if (State == EIPv6SocketInternalState::Yes)
		{
			CurrentState = SCS_Connected;
		}
		else if (State == EIPv6SocketInternalState::No)
		{
			CurrentState = SCS_NotConnected;
		}
	}

	return CurrentState;
}
bool FSocketBSDIPv6::HasPendingData(uint32& PendingDataSize)
{
	// make sure socket has no error state
	if (HasState(EIPv6SocketInternalState::CanRead) == EIPv6SocketInternalState::Yes)
	{
#if PLATFORM_HAS_BSD_SOCKET_FEATURE_IOCTL
		// See if there is any pending data on the read socket
		if(ioctlsocket(Socket, FIONREAD, (u_long*)(&PendingDataSize)) == 0)
#endif
		{
			return (PendingDataSize > 0);
		}
	}

	return false;
}
Beispiel #23
0
bool 
ActionState::GetTransitionPathTo( int target, Path& path ) 
{
	if ( HasState( target ) ) 
	{
		if ( target == m_id )
		{
			ActionState::Node n;

			n.state = this;
			n.code  = ActionState::Node::TARGET;

			path.push_back( n );

			return true;
		}
		else
		{
			ActionState::Node n;

			n.state = this;
			n.code  = ActionState::Node::NOOP; 

			path.push_back( n );

			return getChildPathTo( target, path );
		}
	}
	else
	{
		if ( m_parent != 0 )
		{
			ActionState::Node n;

			n.state = this;
			n.code  = ActionState::Node::EXIT;

			path.push_back( n );

			return m_parent->GetTransitionPathTo( target, path );
		}
	}

	return false; 
}
std::vector<int16_t> Game_Battler::BattleStateHeal() {
	std::vector<int16_t> healed_states;
	std::vector<int16_t>& states = GetStates();

	for (size_t i = 0; i < states.size(); ++i) {
		if (HasState(i + 1)) {
			if (states[i] > Data::states[i].hold_turn
					&& Utils::ChanceOf(Data::states[i].auto_release_prob, 100)) {
				healed_states.push_back(i + 1);
				RemoveState(i + 1);
			} else {
				++states[i];
			}
		}
	}

	return healed_states;
}
std::vector<int16_t> Game_Battler::BattlePhysicalStateHeal(int physical_rate) {
	std::vector<int16_t> healed_states;
	std::vector<int16_t>& states = GetStates();

	if (physical_rate <= 0) {
		return healed_states;
	}

	for (size_t i = 0; i < states.size(); ++i) {
		if (HasState(i + 1) && Data::states[i].release_by_damage > 0) {
			int release_chance = (int)(Data::states[i].release_by_damage * physical_rate / 100.0);

			if (Utils::ChanceOf(release_chance, 100)) {
				healed_states.push_back(i + 1);
			}
		}
	}

	return healed_states;
}
Beispiel #26
0
std::vector<int16_t> Game_Battler::NextBattleTurn() {
	++battle_turn;

	std::vector<int16_t> healed_states;
	std::vector<int16_t>& states = GetStates();

	for (size_t i = 0; i < states.size(); ++i) {
		if (HasState(i + 1)) {
			states[i] += 1;

			if (states[i] >= Data::states[i].hold_turn) {
				if (Utils::ChanceOf(Data::states[i].auto_release_prob, 100)) {
					healed_states.push_back(i + 1);
					RemoveState(i + 1);
				}
			}
		}
	}

	return healed_states;
}
Beispiel #27
0
bool Game_Battler::IsDead() const {
	return HasState(1);
}
void VScrollBarOverlayWindow::UpdateTexture()
{
  int width  = THUMB_WIDTH;
  int height = THUMB_HEIGHT;

  float const aspect = 1.0f;
  float current_x = 0.0f;
  float current_y = 0.0f;

  auto const& bg = nux::color::WhiteSmoke;
  auto const& bg_selected = nux::color::White;
  auto const& bg_active = nux::color::Gray;
  auto const& arrow_color = nux::color::DarkSlateGray;

  auto const& bg_arrow_up = ProduceColorShade(bg, 0.86);
  auto const& bg_arrow_down = ProduceColorShade(bg, 1.1);
  auto const& bg_shadow = ProduceColorShade(bg, 0.2);

  auto const& bg_dark_line = ProduceColorShade(bg, 0.4);
  auto const& bg_bright_line = ProduceColorShade(bg, 1.2);

  nux::CairoGraphics cairoGraphics(CAIRO_FORMAT_ARGB32, THUMB_WIDTH.CP(scale), THUMB_HEIGHT.CP(scale));
  cairo_t* cr = cairoGraphics.GetInternalContext();
  cairo_surface_set_device_scale(cairo_get_target(cr), scale, scale);

  cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR);
  cairo_paint(cr);

  cairo_translate (cr, 0.5, 0.5);
  width--;
  height--;

  cairo_set_line_width (cr, 1.0);

  cairo_set_operator(cr, CAIRO_OPERATOR_OVER);

  // Draw backgound
  SetSourceRGB(cr, bg, 1.0);
  cairoGraphics.DrawRoundedRectangle(cr, aspect, current_x, current_y, THUMB_RADIUS, width, height);
  cairo_fill_preserve(cr);

  // Draw shaded background
  cairo_pattern_t* pat = cairo_pattern_create_linear(0, 0, 0, height);

  PatternAddRGBStop(pat, bg_arrow_up, 0.0, 0.8);
  PatternAddRGBStop(pat, bg_arrow_down, 1.0, 0.8);

  cairo_set_source(cr, pat);
  cairo_pattern_destroy(pat);

  if (current_action_ == ThumbAction::DRAGGING)
  {
    cairo_fill_preserve(cr);
    SetSourceRGB(cr, bg, 0.8);
    cairo_fill(cr);
  }
  else
  {
    cairo_fill(cr);
  }

  // Draw Page Up/Down Action
  if (current_action_ == ThumbAction::PAGE_UP ||
      current_action_ == ThumbAction::PAGE_DOWN)
  {
    if (current_action_ == ThumbAction::PAGE_UP)
      cairo_rectangle(cr, 0, 0, width, height/2);
    else
      cairo_rectangle(cr, 0, height/2, width, height/2);

    SetSourceRGB(cr, bg, 0.8);
    cairo_fill(cr);
  }

  cairo_save(cr);

  // Draw Outline
  cairo_set_line_width (cr, 2.0);

  current_x += 0.5;
  current_y += 0.5;
  cairoGraphics.DrawRoundedRectangle(cr, aspect, current_x, current_y, THUMB_RADIUS - 1, width - 1, height - 1);

  if (HasState(ThumbState::INSIDE_SLIDER))
    SetSourceRGB(cr, bg_selected, 1.0);
  else
    SetSourceRGB(cr, bg_active, 0.9);

  cairo_stroke(cr);

  cairo_restore(cr);

  // Draw shade outline
  pat = cairo_pattern_create_linear(0, 0, 0, height);

  PatternAddRGBStop(pat, bg_shadow, 0.5, 0.06);

  switch(current_action_)
  {
    case ThumbAction::NONE:
      PatternAddRGBStop(pat, bg_shadow, 0.0, 0.22);
      PatternAddRGBStop(pat, bg_shadow, 1.0, 0.22);
      break;
    case ThumbAction::DRAGGING:
      PatternAddRGBStop(pat, bg_shadow, 0.0, 0.2);
      PatternAddRGBStop(pat, bg_shadow, 1.0, 0.2);
      break;
    case ThumbAction::PAGE_UP:
      PatternAddRGBStop(pat, bg_shadow, 0.0, 0.1);
      PatternAddRGBStop(pat, bg_shadow, 1.0, 0.22);
      break;
    case ThumbAction::PAGE_DOWN:
      PatternAddRGBStop(pat, bg_shadow, 0.0, 0.22);
      PatternAddRGBStop(pat, bg_shadow, 1.0, 0.1);
      break;
    default:
      break;
  }

  cairo_set_source(cr, pat);
  cairo_pattern_destroy(pat);

  current_x += 0.5;
  current_y += 0.5;
  cairoGraphics.DrawRoundedRectangle(cr, aspect, current_x, current_y, THUMB_RADIUS, width- 2, height - 2);
  cairo_stroke(cr);

  current_x += 1.0;
  current_y += 1.0;
  cairoGraphics.DrawRoundedRectangle(cr, aspect, current_x, current_y, THUMB_RADIUS - 1, width - 4, height- 4);
  SetSourceRGB(cr, bg_bright_line, 0.6);
  cairo_stroke(cr);

  DrawBothGrips(cr, bg_dark_line, width, height);
  DrawLineSeperator(cr, bg_dark_line, bg_bright_line, width, height);
  DrawBothArrows(cr, arrow_color, width, height);

  thumb_texture_ = texture_ptr_from_cairo_graphics(cairoGraphics);

  QueueDraw();
}
bool Game_Battler::UseSkill(int skill_id, const Game_Battler* source) {
	const RPG::Skill* skill = ReaderUtil::GetElement(Data::skills, skill_id);
	if (!skill) {
		Output::Warning("UseSkill: Can't use skill with invalid ID %d", skill_id);
		return false;
	}

	bool cure_hp_percentage = false;
	bool was_used = false;

	if (skill->type == RPG::Skill::Type_normal || skill->type >= RPG::Skill::Type_subskill) {
		// Only takes care of healing skills outside of battle,
		// the other skill logic is in Game_BattleAlgorithm

		if (!(skill->scope == RPG::Skill::Scope_ally ||
			  skill->scope == RPG::Skill::Scope_party ||
			  skill->scope == RPG::Skill::Scope_self)) {
			return false;
		}

		// Calculate effect:
		float mul = GetAttributeMultiplier(skill->attribute_effects);

		int effect = skill->power;
		if (source != nullptr) {
			effect += source->GetAtk() * skill->physical_rate / 20 +
				source->GetSpi() * skill->magical_rate / 40;
		}
		effect *= mul;

		effect += (effect * Utils::GetRandomNumber(-skill->variance * 10, skill->variance * 10) / 100);

		if (effect < 0)
			effect = 0;

		// Cure states
		for (int i = 0; i < (int)skill->state_effects.size(); i++) {
			if (skill->state_effects[i]) {
				if (skill->reverse_state_effect) {
					was_used |= !HasState(Data::states[i].ID);
					AddState(Data::states[i].ID);
				}
				else {
					was_used |= HasState(Data::states[i].ID);
					RemoveState(Data::states[i].ID);

					// If Death is cured and HP is not selected, we set a bool so it later heals HP percentage
					if (i == 0 && !skill->affect_hp) {
						cure_hp_percentage = true;
					}
				}
			}
		}

		// Skills only increase hp and sp outside of battle
		if (effect > 0 && skill->affect_hp && !HasFullHp() && !IsDead()) {
			was_used = true;
			ChangeHp(effect);
		}
		else if (effect > 0 && cure_hp_percentage) {
			was_used = true;
			ChangeHp(GetMaxHp() * effect / 100);
		}

		if (effect > 0 && skill->affect_sp && !HasFullSp() && !IsDead()) {
			was_used = true;
			ChangeSp(effect);
		}

	} else if (skill->type == RPG::Skill::Type_teleport || skill->type == RPG::Skill::Type_escape) {
		Game_System::SePlay(skill->sound_effect);
		was_used = true;
	} else if (skill->type == RPG::Skill::Type_switch) {
		Game_System::SePlay(skill->sound_effect);
		Game_Switches.Set(skill->switch_id, true);
		was_used = true;
	}

	return was_used;
}
Beispiel #30
0
bool Game_Battler::UseItem(int item_id) {
	const RPG::Item* item = ReaderUtil::GetElement(Data::items, item_id);
	if (!item) {
		Output::Warning("UseItem: Can't use item with invalid ID %d", item_id);
		return false;
	}

	if (item->type == RPG::Item::Type_medicine) {
		bool was_used = false;

		int hp_change = item->recover_hp_rate * GetMaxHp() / 100 + item->recover_hp;
		int sp_change = item->recover_sp_rate * GetMaxSp() / 100 + item->recover_sp;

		if (IsDead()) {
			// Check if item can revive
			if (item->state_set.empty() || !item->state_set[0]) {
				return false;
			}

			// Revive gives at least 1 Hp
			if (hp_change == 0) {
				ChangeHp(1);
				was_used = true;
			}
		} else if (item->ko_only) {
			// Must be dead
			return false;
		}

		if (hp_change > 0 && !HasFullHp()) {
			ChangeHp(hp_change);
			was_used = true;
		}

		if (sp_change > 0 && !HasFullSp()) {
			ChangeSp(sp_change);
			was_used = true;
		}

		for (int i = 0; i < (int)item->state_set.size(); i++) {
			if (item->state_set[i]) {
				was_used |= HasState(Data::states[i].ID);
				RemoveState(Data::states[i].ID);
			}
		}

		return was_used;
	}

	if (item->type == RPG::Item::Type_switch) {
		return true;
	}

	switch (item->type) {
		case RPG::Item::Type_weapon:
		case RPG::Item::Type_shield:
		case RPG::Item::Type_armor:
		case RPG::Item::Type_helmet:
		case RPG::Item::Type_accessory:
			return item->use_skill && UseSkill(item->skill_id);
		case RPG::Item::Type_special:
			return UseSkill(item->skill_id);
	}

	return false;
}