Example #1
0
        public void SetAction(string acStr)
        {
            if (acStr.Equals(_actionStr) || acStr.Equals(""))
            {
                return;
            }
            var acStance = Stance.ByString(acStr);

            if (acStance != Stance.Id.None)
            {
                SetStance(acStance);
            }
            else
            {
                Action = _drawInfo.GetAction(acStr, 0);
                if (Action == null)
                {
                    return;
                }
                _actFrame  = 0;
                _steLapSed = 0;
                _actionStr = acStr;
                _stance.Set(Action.Stance());
                _stFrame.Set(Action.GetFrame());
            }
        }
Example #2
0
 public void Reset()
 {
     _flip      = true;
     Action     = null;
     _actionStr = "";
     _actFrame  = 0;
     SetStance(Stance.Id.Stand1);
     _stFrame.Set(0);
     _steLapSed = 0;
     SetExpression(Expression.Id.Default);
     _expFrame.Set(0);
     _expELapSed = 0;
 }
Example #3
0
        public bool Update(short timeStep)
        {
            // todo
            if (timeStep == 0)
            {
                _stance.Normalize();
                _stFrame.Normalize();
                _expression.Normalize();
                _expFrame.Normalize();
            }

            _alerted.Update();
            var aniEnd = false;

            if (Action == null)
            {
                var delay = GetDelay(_stance.Get(), _stFrame.Get());
                var delta = delay - _steLapSed;
                if (timeStep >= delta)
                {
                    _steLapSed = (short)(timeStep - delta);
                    var nextFrame = GetNextFrame(_stance.Get(), _stFrame.Get());
                    var threshold = (float)delta / timeStep;
                    _stFrame.Next(nextFrame, threshold);
                    if (_stFrame.Get() == 0)
                    {
                        aniEnd = true;
                    }
                }
                else
                {
                    _stance.Normalize();
                    _stFrame.Normalize();
                    _steLapSed += timeStep;
                }
            }
            else
            {
                var delay = Action.Delay;
                var delta = (short)(delay - _steLapSed);
                if (timeStep >= delta)
                {
                    _steLapSed = (short)(timeStep - delta);
                    _actFrame  = _drawInfo.NextActionFrame(_actionStr, _actFrame);
                    if (_actFrame > 0)
                    {
                        Action = _drawInfo.GetAction(_actionStr, _actFrame);
                        var threshold = (float)delta / timeStep;
                        _stance.Next(Action.Stance(), threshold);
                        _stFrame.Next(Action.GetFrame(), threshold);
                    }
                    else
                    {
                        aniEnd     = true;
                        Action     = null;
                        _actionStr = "";
                        SetStance(Stance.Id.Stand1);
                    }
                }
                else
                {
                    _stance.Normalize();
                    _stFrame.Normalize();
                    _steLapSed += timeStep;
                }
            }

            var expDelay = Face.GetDelay(_expression.Get(), _expFrame.Get());
            var expDelta = expDelay - _expELapSed;

            if (timeStep >= expDelta)
            {
                _expELapSed = (short)(timeStep - expDelta);
                var nextExpFrame = Face.NextFrame(_expression.Get(), _expFrame.Get());
                var fcThreshold  = (float)expDelta / timeStep;
                _expFrame.Next(nextExpFrame, fcThreshold);
                if (_expFrame.Get() == 0)
                {
                    _expression.Next(
                        _expression.Get() == Expression.Id.Default ? Expression.Id.Blink : Expression.Id.Default,
                        fcThreshold);
                }
            }
            else
            {
                _expression.Normalize();
                _expFrame.Normalize();
                _expELapSed += timeStep;
            }

            return(aniEnd);
        }
Example #4
0
        public BodyDrawInfo()
        {
            var bodyNode = (WzImage)Wz.Character["00002000.img"];
            var headNode = (WzImage)Wz.Character["00012000.img"];

            _bodyPositions = new Dictionary <Stance.Id, Dictionary <short, Vector2> >();
            _armPositions  = new Dictionary <Stance.Id, Dictionary <short, Vector2> >();
            _handPositions = new Dictionary <Stance.Id, Dictionary <short, Vector2> >();
            _headPositions = new Dictionary <Stance.Id, Dictionary <short, Vector2> >();
            _hairPositions = new Dictionary <Stance.Id, Dictionary <short, Vector2> >();
            _facePositions = new Dictionary <Stance.Id, Dictionary <short, Vector2> >();
            _stanceDelays  = new Dictionary <Stance.Id, Dictionary <short, short> >();
            _bodyActions   = new Dictionary <string, Dictionary <short, BodyAction> >();
            _attackDelays  = new Dictionary <string, List <short> >();
            foreach (var stanceNode in bodyNode.WzProperties)
            {
                if (stanceNode is WzSubProperty)
                {
                    var stStr = stanceNode.Name;
                    if (stStr.Equals("dead"))
                    {
                        Console.WriteLine();
                    }

                    short attackDelay = 0;
                    for (short frame = 0; frame < stanceNode.WzProperties.Count; frame++)
                    {
                        WzObject frameNode = stanceNode.WzProperties[frame];
                        if (frameNode is WzSubProperty)
                        {
                            if (frameNode["action"] is WzStringProperty)
                            {
                                var action = new BodyAction((WzSubProperty)frameNode);
                                if (!_bodyActions.ContainsKey(stStr))
                                {
                                    _bodyActions[stStr] = new Dictionary <short, BodyAction>();
                                }
                                _bodyActions[stStr][frame] = action;
                                if (action.IsAttackFrame())
                                {
                                    if (!_attackDelays.ContainsKey(stStr))
                                    {
                                        _attackDelays[stStr] = new List <short>();
                                    }
                                    _attackDelays[stStr].Add(attackDelay);
                                }

                                attackDelay += action.Delay;
                            }
                            else
                            {
                                var stance = Stance.ByString(stStr);
                                if (stance == Stance.Id.None)
                                {
                                    continue;
                                }
                                short delay = 0;
                                if (frameNode["delay"] != null)
                                {
                                    delay = (short)frameNode["delay"];
                                }
                                if (delay <= 0)
                                {
                                    delay = 100;
                                }
                                if (!_stanceDelays.ContainsKey(stance))
                                {
                                    _stanceDelays[stance] = new Dictionary <short, short>();
                                }
                                _stanceDelays[stance][frame] = delay;
                                var bodyShiftMap = new Dictionary <Body.Layer, Dictionary <string, Vector2> >();
                                foreach (var partNode0 in ((WzSubProperty)frameNode).WzProperties)
                                {
                                    var partNode = partNode0.GetByUol();
                                    if (partNode is WzCanvasProperty)
                                    {
                                        var zStr = ((WzStringProperty)partNode["z"]).Value;
                                        var z    = Body.LayerByName(zStr);
                                        var map  = (WzSubProperty)partNode["map"];
                                        foreach (var innerMap in map.WzProperties)
                                        {
                                            if (innerMap is WzVectorProperty)
                                            {
                                                if (!bodyShiftMap.ContainsKey(z))
                                                {
                                                    bodyShiftMap[z] = new Dictionary <string, Vector2>();
                                                }
                                                bodyShiftMap[z][innerMap.Name] = (Vector2)innerMap.WzValue;
                                            }
                                        }

                                        var headMap = headNode[stStr]?[frame.ToString()]["head"]["map"]
                                                      .WzProperties;
                                        if (headMap != null)
                                        {
                                            foreach (var mapNode in headMap)
                                            {
                                                if (mapNode is WzVectorProperty)
                                                {
                                                    if (!bodyShiftMap.ContainsKey(Body.Layer.Head))
                                                    {
                                                        bodyShiftMap[Body.Layer.Head] =
                                                            new Dictionary <string, Vector2>();
                                                    }
                                                    bodyShiftMap[Body.Layer.Head][mapNode.Name] =
                                                        (Vector2)mapNode.WzValue;
                                                }
                                            }
                                        }

                                        if (!_bodyPositions.ContainsKey(stance))
                                        {
                                            _bodyPositions[stance] = new Dictionary <short, Vector2>();
                                        }
                                        _bodyPositions[stance][frame] =
                                            bodyShiftMap.GetVector2(Body.Layer.Body, "navel");
                                        if (!_armPositions.ContainsKey(stance))
                                        {
                                            _armPositions[stance] = new Dictionary <short, Vector2>();
                                        }
                                        _armPositions[stance][frame] =
                                            bodyShiftMap.ContainsKey(Body.Layer.Arm)
                                                ? bodyShiftMap.GetVector2(Body.Layer.Arm, "hand") -
                                            bodyShiftMap.GetVector2(Body.Layer.Arm, "navel") +
                                            bodyShiftMap.GetVector2(Body.Layer.Body, "navel")
                                                : bodyShiftMap.GetVector2(Body.Layer.ArmOverHair, "hand") -
                                            bodyShiftMap.GetVector2(Body.Layer.ArmOverHair, "navel") +
                                            bodyShiftMap.GetVector2(Body.Layer.Body, "navel");
                                        if (!_handPositions.ContainsKey(stance))
                                        {
                                            _handPositions[stance] = new Dictionary <short, Vector2>();
                                        }
                                        _handPositions[stance][frame] =
                                            bodyShiftMap.GetVector2(Body.Layer.HandBelowWeapon, "handMove");
                                        if (!_headPositions.ContainsKey(stance))
                                        {
                                            _headPositions[stance] = new Dictionary <short, Vector2>();
                                        }
                                        _headPositions[stance][frame] =
                                            bodyShiftMap.GetVector2(Body.Layer.Body, "neck") -
                                            bodyShiftMap.GetVector2(Body.Layer.Head, "neck");
                                        if (!_facePositions.ContainsKey(stance))
                                        {
                                            _facePositions[stance] = new Dictionary <short, Vector2>();
                                        }
                                        _facePositions[stance][frame] =
                                            bodyShiftMap.GetVector2(Body.Layer.Body, "neck") -
                                            bodyShiftMap.GetVector2(Body.Layer.Head, "neck") +
                                            bodyShiftMap.GetVector2(Body.Layer.Head, "brow");
                                        if (!_hairPositions.ContainsKey(stance))
                                        {
                                            _hairPositions[stance] = new Dictionary <short, Vector2>();
                                        }
                                        _hairPositions[stance][frame] =
                                            bodyShiftMap.GetVector2(Body.Layer.Head, "brow") -
                                            bodyShiftMap.GetVector2(Body.Layer.Head, "neck") +
                                            bodyShiftMap.GetVector2(Body.Layer.Body, "neck");
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }