コード例 #1
0
ファイル: npc.cpp プロジェクト: is0urce/press-x-rail
		void npc::action_unit(environment &current)
		{
			person::action_unit(current);

			point dest = current.player()->position();

			if (m_ai_state == ai_state::idle)
			{
				if (current.distance(dest, position()) <= alert_distance || !health().full())
				{
					m_ai_state = ai_state::alert;
					current.broadcast({ "!", 0xff0000, position(), 1.0 });
				}
			}
			else if (m_ai_state == ai_state::alert)
			{
				auto scene = current.scene();
				auto path = path::find(position(), dest, 50, [&](const point &p) { return scene->traversable(p); });
				if (path)
				{
					auto step = path->begin();
					if (step != path->end())
					{
						auto blocking = scene->blocking(*step);
						if (blocking && !blocking->invincible())
						{
							for (auto &skill : m_skills)
							{
								if (skill.targeted() && skill.useable(this, blocking))
								{
									skill.use(this, blocking);
									break;
								}
								else if (skill.useable(this, dest))
								{
									skill.use(this, dest);
									break;
								}
							}
						}
						else
						{
							scene->move(*this, *step);
						}
					}
				}
			}
		}