123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- public class SimpleExperienceSystem : IExperienceSystem
- {
- public SimpleExperienceSystem()
- {
- }
- public SimpleExperienceSystem(List<int> need_exp_list)
- {
- this.SetExreienceList(need_exp_list);
- }
- protected SimpleExperienceSystem(SimpleExperienceSystem other) : base(other)
- {
- this.need_exp_list_ = new List<int>(other.need_exp_list_);
- }
- public void SetExreienceList(List<int> need_exp_list)
- {
- if (need_exp_list == null || need_exp_list.Count <= 0)
- {
- this.need_exp_list_ = null;
- this.Update();
- return;
- }
- this.need_exp_list_ = need_exp_list;
- NDebug.Assert(0 < this.need_exp_list_.Count, "There is no element.");
- this.Update();
- }
- public override int GetMaxLevel()
- {
- return (this.need_exp_list_ != null) ? this.need_exp_list_.Count : 0;
- }
- protected override int GetNeedExp(int level)
- {
- if (this.need_exp_list_ == null)
- {
- return 0;
- }
- return this.need_exp_list_[level - 1];
- }
- public override void Serialize(BinaryWriter binary)
- {
- base.Serialize(binary);
- }
- public override void Update()
- {
- int level_ = this.level_;
- base.Update();
- if (level_ != this.level_ && this.onChangeLevelEvent != null)
- {
- this.onChangeLevelEvent(this);
- }
- }
- public void SerializeAll(BinaryWriter binary)
- {
- this.Serialize(binary);
- if (this.need_exp_list_ == null)
- {
- int value = 0;
- binary.Write(value);
- }
- else
- {
- binary.Write(this.need_exp_list_.Count);
- for (int i = 0; i < this.need_exp_list_.Count; i++)
- {
- binary.Write(this.need_exp_list_[i]);
- }
- }
- }
- public void DeserializeAll(BinaryReader binary, int version)
- {
- this.Deserialize(binary, version);
- int num = binary.ReadInt32();
- if (num <= 0)
- {
- this.need_exp_list_ = null;
- }
- else
- {
- if (this.need_exp_list_ == null)
- {
- this.need_exp_list_ = new List<int>();
- }
- this.need_exp_list_.Clear();
- for (int i = 0; i < num; i++)
- {
- this.need_exp_list_.Add(binary.ReadInt32());
- }
- }
- }
- public override object Clone()
- {
- return new SimpleExperienceSystem(this);
- }
- public Action<SimpleExperienceSystem> onChangeLevelEvent;
- protected List<int> need_exp_list_;
- }
|