Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Microsoft.Xna.Framework;
- using mrogue.Components;
- using mrogue.Interface;
- using mrogue.Service;
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Linq;
- using mrogue.World;
- namespace mrogue
- {
- /// <summary>
- /// Root orchestrator for an object in the game world.
- /// Contains a collection of Components that define the Actor's behavior
- /// </summary>
- public class Actor : Entity
- {
- private static NLog.Logger log = NLog.LogManager.GetCurrentClassLogger();
- public Point Position { get; set; }
- public int Elevation { get; set; }
- public Map Map { get; set; }
- private Dictionary<Type, Component> Components { get; set; }
- public MovementComponent Movement {
- get => GetComponent<MovementComponent>();
- }
- public CombatComponent Combat
- {
- get => GetComponent<CombatComponent>();
- }
- public PlayerComponent Player
- {
- get => GetComponent<PlayerComponent>();
- }
- public ItemComponent Item
- {
- get => GetComponent<ItemComponent>();
- }
- public InventoryComponent Inventory
- {
- get => GetComponent<InventoryComponent>();
- }
- public Actor()
- {
- Components = new Dictionary<Type, Component>();
- }
- public Actor(params Component[] components)
- {
- Components = new Dictionary<Type, Component>();
- foreach (Component c in components)
- {
- c.Actor = this;
- Components.Add(c.GetType(), c);
- if(c is ItemComponent itemComponent)
- {
- this.PrintableName = itemComponent.Item.PrintableName;
- this.Description = itemComponent.Item.Description;
- this.Glyph = itemComponent.Item.Glyph;
- }
- }
- }
- public T GetComponent<T>() where T : Component
- {
- var key = typeof(T);
- if (Components.ContainsKey(key))
- {
- return Components[key] as T;
- }
- else
- {
- return null;
- }
- }
- public void SetComponent<T>(T component) where T : Component
- {
- Components[typeof(T)] = component;
- component.Actor = this;
- }
- public bool HasComponent<T>() where T : Component
- {
- return Components.ContainsKey(typeof(T));
- }
- public void OnTick()
- {
- foreach(var component in Components.Values)
- {
- component.OnTick();
- }
- }
- /// <summary>
- /// Sets the actor's position and recalculates the game state
- /// </summary>
- /// <param name="position"></param>
- public ActionResult SetPosition(Point position)
- {
- log.Info("Setting actor postion {0}", position);
- var oldPosition = Position;
- var oldElevation = Elevation;
- this.Position = position;
- this.Elevation = Map[Position].Elevation;
- //TODO - Maybe may a rules system or something?
- //TODO - Update changed tiles if we ever have a changed tiles list
- //TODO - Update FoV map
- //TODO - Update pathfinding
- //TODO - Trigger step event
- //TODO - Handle status changes (slugish, agile)
- //TODO - Handle falling in a pit
- //TODO - If is player, update global FoV
- //TODO - Handle light recalculation
- return ActionResult.Success;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement