Esempio n. 1
0
    public CharacterRecord(EB.Sparx.CharacterData data)
    {
        _characterRecordEntries = new List <ICharacterRecordEntry>();

        CustomizationRecord = new CharacterRecordEntryCustomization();
        _characterRecordEntries.Add(CustomizationRecord);

        AbilitiesRecord = new CharacterRecordEntryAbilities();
        _characterRecordEntries.Add(AbilitiesRecord);

        StatisticsRecord = new CharacterRecordEntryStatistics();
        _characterRecordEntries.Add(StatisticsRecord);

        //ToDo:
        //QuestsRecord = new CharacterRecordEntryQuests();
        //_characterRecordEntries.Add(QuestsRecord);

        ProgressFlagsRecord = new CharacterRecordEntryProgressFlags();
        _characterRecordEntries.Add(ProgressFlagsRecord);

        EquipmentRecord = new SecureCharacterRecordEntryEquipment(this);
        GeneralRecord   = new SecureCharacterRecordEntryGeneral(this);

        foreach (ICharacterRecordEntry entry in _characterRecordEntries)
        {
            entry.Initialize();
        }
        EquipmentRecord.Initialize();
        GeneralRecord.Initialize();

        if (null == data)
        {
            return;
        }

        int characterId = data.Id;

        if (characterId < 0)
        {
            LoadState = LoadStateType.Failed;
            return;
        }

        PortraitId = data.PortraitId;

#if DEBUG
        //DebugSystem.RegisterInstance("Character " + characterId, this, "Character");
#endif

        LoadState = LoadStateType.Loading;
        Load(data);

#if DEBUG
        if (LoadStateType.Failed == LoadState)
        {
            //DebugSystem.UnregisterSystem(this);
        }
#endif
    }
Esempio n. 2
0
    public void CreateCharacter(Hashtable properties, Hashtable generalRecord, System.Action <EB.Sparx.eResponseCode, CharacterRecord> callback)
    {
        _api.Create(properties, generalRecord, delegate(EB.Sparx.eResponseCode response, Hashtable result)
        {
            CharacterRecord characterRecord = null;

            if (response == EB.Sparx.eResponseCode.Success)
            {
                EB.Sparx.CharacterData data = new EB.Sparx.CharacterData(EB.Dot.Object("character", result, null));
                characterRecord             = new CharacterRecord(data);
                _characterRecordPreviewMap[characterRecord.Id] = characterRecord;
            }

            if (null != callback)
            {
                callback(response, characterRecord);
            }
        });
    }
Esempio n. 3
0
    public void GetAllCharacters(System.Action <EB.Sparx.eResponseCode> callback)
    {
        if (_isLoading)
        {
            return;
        }

        _isLoading = true;

#if DEBUG
        DebugSystem.Log(this, "Loading Characters");
#endif

        _api.GetAll(delegate(EB.Sparx.eResponseCode response, Hashtable result)
        {
            _isLoading = false;

            if (response == EB.Sparx.eResponseCode.Success)
            {
                _characterRecordPreviewMap.Clear();
                ArrayList characters = EB.Dot.Array("characters", result, new ArrayList());

                foreach (Hashtable character in characters)
                {
                    EB.Sparx.CharacterData characterData = new EB.Sparx.CharacterData(character);

                    if (characterData.Id >= 0)
                    {
                        CharacterRecord characterRecord = new CharacterRecord(characterData);
                        _characterRecordPreviewMap[characterData.Id] = characterRecord;
                    }
                }

                IsLoaded = true;
                //EventManager.instance.Raise(new OnCharacterLoadedEvent());
            }

            if (null != callback)
            {
                callback(response);
            }
        });
    }
Esempio n. 4
0
    public void Load(EB.Sparx.CharacterData data)
    {
        LoadState = LoadStateType.Loading;

        if (data.Id < 0)
        {
            LoadState = LoadStateType.Failed;
            return;
        }

        Id         = data.Id;
        PortraitId = data.PortraitId;

#if DEBUG
        DebugSystem.Log(this, "load character: " + Id);
#endif

        foreach (ICharacterRecordEntry entry in _characterRecordEntries)
        {
            ReadFromHashtable(entry, data.Properties[entry.GetType().ToString()] as Hashtable);
        }

        EquipmentRecord.Load(data.Equipment);
        GeneralRecord.Load(data.General);

        if (LoadStateType.Loading == LoadState)
        {
            SparxCharacterData = data;
            LoadState          = LoadStateType.Loaded;
        }

        if (LoadEvent != null)
        {
            LoadEvent();
        }

        //EventManager.instance.Raise(new CharacterRecordReloadEvent());
    }